Issue with a rbv_api.getRelatedFields formula - Forum - Rollbase - Progress Community

Issue with a rbv_api.getRelatedFields formula

 Forum

Issue with a rbv_api.getRelatedFields formula

  • I'm still having issue with how rbv_api.getRelatedFields is implemented in latest builds. If I'm trying to use is it intended for example var description = rbv_api.getRelatedFields('R62551360', {!id}, 'mode_of_import#code'); return description.join(", "); formula is working but I'm not able to create new records because of the system error. Work around is using catch(e) like so try {var description = rbv_api.getRelatedFields('R62551360', {!id}, 'mode_of_import#code'); return description.join(", "); } catch(e) { return ''; } But with this solution I'm getting new issue: when creating new record related information is not being automatically imported on save (fields with getRelatedFields stay blank). To pull related information I need to click on edit and then save record again. This is very inconvenient and my users are not able to comprehend it. Please take a look at this issue and see if you can fix it.
  • Hi Roman,



    I have promoted this issue internally and we will get back to you by next week with an update.



    Regards,

    Matt
  • Can you provide with me with an estimated date when this bug will be fixed?

    I just tested again api.getRelatedFields and again I was not able to save newly crated record.



    Regards,

    Roman
  • Hi Roman,



    Our current position on this is that it is not a bug, you need to make sure you do not pass empty values to this method.



    In other words make sure you do not call this API method on a non-existing record, otherwise an exception will be thrown. This is a case that, at least for now, you need to make sure your JavaScript can handle.



    Let me know if this isn't clear or if you disagree,

    Matt
  • Hi Roman,



    Add a handler instead of a try-catch before you fire your trigger.



    e.g.

    1.Using ID Single checking - For many:1 relationships



    if ( parseInt("{!R62551360#id}") > 0 ) {

    //... code

    }





    2. Using Count of Dependent Multiple checking - For many:many or 1:many relationships



    if ( parseInt("#CALC_COUNT.R62551360( 1 | true )") > 0 ) {

    //... code

    }





    Hope this helps,

    Piscoso, Martin

    Rollbase
  • Martin,



    Thank you for your effort but your solutions are not working. In both cases when I was trying to create a new record and simultaneously attach to that new record a related record, I got a system error that prevented me from saving it.

    Only option that is working right now is "catch(e)" but then when I'm saving a new record all related information is not showing and only when I'm clicking on edit and then save record again system is retrieving all the related fields.

    It would be nice to have a complete solution for this problem.



    Regards,

    Roman
  • Hi Roman,



    R62551360 >> How is this relationship/field populated after create? it seems that there are no related records which gives you the error. See inquiries below



    Re: In both cases when I was trying to create a new record and simultaneously attach to that new record a related record



    the getRelatedFields call is for records which are "already" linked.

    I think that is where the error lies, it is possible that on create, your records aren't really linked at all.



    Re: when I'm saving a new record all related information is not showing and only when I'm clicking on edit and then save record again system is retrieving all the related fields.



    It is possible that the building of the relationship between the records are trigger based? or is the relationship only set "after update" of a record? this might also be a cause of your issue.



    --------------------------------------------



    In this case, can you provide the scenario/requirement that you are trying to achieve? e.g. Process flow



    This
  • Martin,



    I'm not using any triggers.











    Instead of catch(e) I was trying to use your solutions but I was not able to create a new record in "Levy Exemption" because of the system error.

    As of end result I want that for all new record in "Levy Exemption" all related fields from "Levy Exemption Request" were populated on "Save". Right now all related field stay empty till I re-save newly created record.

  • Hi Roman,



    How are you relating "Levy Exemption" to "Levy Exemption Request" ?



    Are they being created through a grid? e.g.



    - Levy Exemption (new page) has Levy Exemption Request Grid ?



    Or are they being looked up? e.g.



    - Levy Exemption (new page) has Levy Exemption Request Lookup ?



    Your code would depend on these factors greatly since it seems that upon create of your Levy Exemption, the related Exemption Requests aren't recognized until the edit operation.



    -----------------------------------------------------------------



    For the Field "Calc Contractor", what is the field type? Expression?



    Can you try and return this simple token during the create operation:



    return parseInt("#CALC_COUNT.R67439733( 1 | true )");



    It is so that we can count your related "Levy Exemption Requests" upon create of your "Levy Exemption"



    Additionally, create a formula field and place the same code:



    return parseInt("#CALC_COUNT.R67439733( 1 | true )");



    I'm trying to ide
  • Martin,



    I'm using lookup.



    I just found out that if I'm using Formula (String) field instead of Expression (String) I'm not facing problem with fields from related object during creation of new records

    I'm using original formula:

    var contractor= rbv_api.getRelatedFields('R67439733', {!id}, 'contractor#code');

    return contractor.join(", ");



    I need to use Expressions so I can filter records.
  • Roman,



    I see. I believe what you're facing is in fact an expression field issue.



    What you can do instead of using a expression field, is to use a text/picklist/lookup field and a trigger (with the orig formula) to update the field's value with you're getRelatedFields variable.



    Text - if you're using inputted filters

    Picklist - if the values are static

    Lookup - if the records reside on another object and need to be related to the Levy Exemption.



    > New Field

    > Update Field Value Trigger (After Create/Update)

    Use you're original Formula:



    var contractor= rbv_api.getRelatedFields('R67439733', {!id}, 'contractor#code');

    return contractor.join(", ");





    Not sure how you've implemented you're filters so I'll leave it to you to choose the field type.



    ---------------------------------------------------------------------



    I think what you encountered is a separate issue and so should be posted on another topic or you could file a support ticket for this.



    e.g. Expression fields
  • Expression fields are not designed to use related fields because they do not automatically get updated when a related record gets updated. By using related fields in expression fields you will be definition be storing values that may be out of date moments after they are stored. You can include the result of a formula in an expression field if you really want to work around this limitation but this is a workaround, not an actual solution that will update the expression field whenever a related field is changed.



    Hope this helps,

    Matt
  • Martin,



    Greatly appreciate your help!

    I filed support ticket for malfunction of expression fields. Hopeful it will be fixed soon.

    I will try to test your solution with triggers today and post my results.



    Regards,

    Roman