Forum Discussion

SMK's avatar
SMK
Qrew Trainee
3 days ago

Prefilled Value with a Button

Hi everyone,

I’ve created a “Copy Line Item” button that is supposed to create a new record and prefill it with the same values selected by the user in the original record.

The button works, but I’m running into an issue: the following fields are not being prefilled when the new record is created:

[Related Trademark]
[Related Beverage Type]
[Related Package]


All three of these fields are text field types, populated through relationships from their parent tables. The values that show up in them are alphanumeric (e.g., A1, B1, C700, etc.), and they are key fields in their respective tables.

For some reason, when I click the button, these related fields don’t carry over into the new record. Has anyone run into this issue before, or know how to get these relationship-based fields to prefill correctly?

 

For reference the code is in the attachment section. 


var text nonNational  = URLRoot() & "db/" & [_DBID_PR_LINE_ITEMS] & "?a=API_GenAddRecordForm&dfid=22&_fid_13=" & URLEncode([Related Price Request]) 
    & "&_fid_10=" & URLEncode([Start Date]) 
    & If(IsNull([End Date]), "&_fid_11=" & URLEncode("2050-12-31"), "&_fid_11=" & URLEncode([End Date])) 
    & "&_fid_12=" & URLEncode([Rate]) 
    & "&_fid_6=" & URLEncode([Customer Option]) &
        If([Customer Option] = "Customer", "&_fid_376=" & URLEncode([Related Customer4])
        , [Customer Option] = "Local Chain","&_fid_360=" & URLEncode([Regional Account - LocalChainId])
        , [Customer Option] = "Promo Plan","&_fid_365=" & URLEncode([Related RegionalPromo])
        , [Customer Option Channel] = "Channel","&_fid_34=" & URLEncode([Related Market]) 
        )
    & "&_fid_85=" & URLEncode([Geography Option]) &
        If([Geography Option] = "Included All Price Zone", ""
        , [Geography Option] = "Specific Price Zone","&_fid_73=" & URLEncode([Related Price Zone])
        , [Geography Option] = "Specific Sales Office","&_fid_73=" & URLEncode([Related Price Zone]) & "&_fid_74=" & URLEncode([Related Price Zone - Sales Office Relationship])
        )
    & "&_fid_55=" & URLEncode([Product Option]) &
        If([Product Option] = "Material", "&_fid_70=" & URLEncode([Related Material])
        , [Product Option] = "Beverage Type & Package Size","&_fid_42=" & URLEncode([Related Beverage Type]) & "&_fid_46=" & URLEncode([Related Beverage Type - Package Relationship])
        , [Product Option] = "Trademark & Package Size","&_fid_50=" & URLEncode([Related Trademark]) & "&_fid_52=" & URLEncode([Related Trademark - Package Relationship])
        , [Product Option] = "Package Size Only","&_fid_72=" & URLEncode([Related Package])
        );
      $nonNational


Thanks in advance for your help!

4 Replies

  • Mez's avatar
    Mez
    Qrew Captain
    SMK wrote:

    If([Customer Option] = "Customer", "&_fid_376=" & URLEncode([Related Customer4])
            , [Customer Option] = "Local Chain","&_fid_360=" & URLEncode([Regional Account - LocalChainId])
            , [Customer Option] = "Promo Plan","&_fid_365=" & URLEncode([Related RegionalPromo])
            , [Customer Option Channel] = "Channel","&_fid_34=" & URLEncode([Related Market]) 
            )

    Should you break out "Customer Option" from "Customer Option Channel" in this first if statement?

    Since you're encoding each of these values (Customer, Geographic, and Product Option) just prior to your If() logic, what happens if there is no value for these fields? Is there just a double ampersand - "&&"? 

    When formulas like this one don't seem to be what I'm expecting, I like to use either the "check my formula" option from within the field settings, or take a small chunk of this code and create a report to use report variables to see the data generated. 

    *edit: just wondering if you take your last bit of code and put it into a report formula, what generates?

    var text sample = "&_fid_55=" & URLEncode([Product Option]) &
    If(

      [Product Option] = "Material",  "&_fid_70=" & URLEncode([Related Material]),

      [Product Option] = "Beverage Type & Package Size", "&_fid_42=" & URLEncode([Related Beverage Type]) & "&_fid_46=" & URLEncode([Related Beverage Type - Package Relationship]),

      [Product Option] = "Trademark & Package Size", "&_fid_50=" & URLEncode([Related Trademark]) & "&_fid_52=" & URLEncode([Related Trademark - Package Relationship]),

      [Product Option] = "Package Size Only", "&_fid_72=" & URLEncode([Related Package])
    );

    $sample

  • It is possible that this part of your IF statement here

     

    [Product Option] = "Trademark & Package Size","&_fid_50=" & URLEncode([Related Trademark]) 

    Is looking for the value, exactly spelled Trademark & Package Size

     Maybe that is not exactly what it has in the field so that part of the IF is not triggering.  I suggest that you make a new formula text field equal to this button field and then you will have a debug field to be able to examine the result of that long formula. Then you will see if in fact the formula is trying to put something into field 50 and if so, what is trying to put into there.

     

  • SMK's avatar
    SMK
    Qrew Trainee

    Yes, the [Related Trademark] field ID is 50 in PR line Item table. The button is created in PR Line Item table.  As per my knowledge, the related trademark in Child Table(PR Line Items) is the reference of the key field on parent table(Trademark). Since, Each Trademark can have multiple line items.

    I have attached the URL when the user inputs the values(BOLDED) and the relationship between both tables PR Line Items and Trademarks.

  • Well, you should double check that when you populate the reference field on the right side of the relationship for related parent, that you are putting the value into the correct field ID. Also note that you cannot populate look up fields, you only populate the related parent field, and all the look up fields will come in on their own.   

    If we take one example for [Related Trademark] can you check in your relationship if the field ID for [Related Trademark] is in fact field ID 50?