auto populate lookup field from another lookup field

I have two account lookup fields in a custom object, Billing Account and Shipping Account. On selection of Billing Account, I want the Shipping Account to be auto populated if the checkbox field ‘Same as Above’ is set to true. 

I have a snippet built on the mobile page where I could get all address information autopopulated from Billing Account to custom fields (such as street, city, state, zip) on checking ‘same as above’, but I wasn’t able to get Shipping Account lookup field autopopulated from Billing Account. 

How can I get the Shipping Account field autopopulated too?

Here is my code:

skuid.$(document).ready(function() {    setTimeout(initSignature, 500);
    returnsModel = skuid.model.getModel(‘FormData’);
    FormDatafirstrow = returnsModel.getFirstRow();
    calculatedDaysReturned(FormDatafirstrow.Date_Received__c);
    sameAsAbove(FormDatafirstrow.Same_As_Above__c);
    attachmentsModel = skuid.model.getModel(‘Attachments’);
    AuthProdReturnRecType = skuid.model.getModel(‘RecordType’).getFirstRow().Id;
    FormLineItemModel = skuid.model.getModel(‘FormLineItemData’);
});

function sameAsAbove(value){
   // console.log('SAME AS ABOVE = '+value);
   // console.log('Accountvalue = '+Accountvalue);
    
    if(value === true && Accountvalue !== undefined){
    
        var Account = skuid.model.getModel(‘Account’);
        var ANcondition = Account.getConditionByName(‘Id’);
        Account.setCondition(ANcondition,Accountvalue);
        var AccountRow = Account.data[0];
        
        //console.log('Account = '+Account);

        Account.updateData(function(){
            var aCount = Account.getFirstRow().BillingCountry;
            
           returnsModel.updateRow(FormDatafirstrow, {Street_Address__c : Account.getFirstRow().BillingStreet,
                                                    City__c : Account.getFirstRow().BillingCity,
                                                    State_Province__c : Account.getFirstRow().BillingState,
                                                    Zip_Postal_Code__c : Account.getFirstRow().BillingPostalCode,
                                                    Country__c : aCount,
                                                    ///Shipping_Account__c : Account.getFirstRow().Name + ’ ‘+Account.getFirstRow().BillingCity+’ - '+ Account.getFirstRow().Address_Number__c
                                                    //Shipping_Account__c : Account.getFirstRow().Id
                                                   
                                                });
           
            });
    }

You should be able to do a model action that is triggered by checking the box that updates your shipping address fields with the corresponding billing account fields.


I do not see model action on mobile page. It gives me option only to either ‘Clone’ or ‘Remove this Model’ under Actions. I know on Desktop page we have this option to update row in model under action. But could you please suggest me on how I can do this on skuid mobile page?

This post may help: https://community.skuid.com/t/mobile-builder-models-have-no-model-actions

Thanks for your suggestion. I created a desktop page to setup model action so that i can copy the xml to my mobile page. So my desktop has only 2 fields, ‘Billing Account’, ‘Same as above’ and ‘Shipping Account’. 

I have two models, Account and a custom object. Account having condition with filterable default off. I am setting the action on custom object model, when ‘Same as above’ is updated,
i. Activate and set the Account Id on Account model (Account from custom object)
ii. Query Model Account
iii. Update field on row ‘Shipping Address’ value : {{$Model.Account.data.0.Name}}

This is populating the same account to shipping address correctly, but it disappears after few seconds. And also, the checkbox ‘Same as above’ work for the first time only after page launch.

Please suggest.

If memory serves correctly, you can’t bring in the name field directly into a reference field. The reference field is tied to the Id. So I think you would have to do two actions. Action 1 populates the field with the Id. This will look sloppy as it will be the ID instead of address… You can the overwrite it with action 2 to repopulate it with Name. It happens instantaneously so no one should even notice. As for the check box working only once… I’m not sure about that. Fixing the above may fix it or it may be a glitch. If you can’t get it to work, I would report it as a bug.

That worked like charm! Thank you.

One last question. Instead of saying if ‘Same as above’ is updated, is there a way to say if ‘Same as above’ is true only then trigger the actions. Because, every time the ‘Same as above’ is updated to true/false, the account is getting updated.I want the account to get autopopulated only if ‘Same as above’ is set to true


That worked like charm! Thank you.

One last question. Instead of saying if ‘Same as above’ is updated, is there a way to say if ‘Same as above’ is true only then trigger the actions. Because, every time the ‘Same as above’ is updated to true/false, the account is getting updated.I want the account to get autopopulated only if ‘Same as above’ is set to true


I think you are out of luck there. Skuid does not, to my knowledge have conditional actions yet. It has been requested as a new feature in other posts. You could search the community and vote them up.

Pavithra,  you can use a javascript snippet to create a conditional situation.  Use the Jquery Deferred method to return a success and failure branch out of your snippet.  (Lots of posts on the community about this method)  The Javascript snippet action has “on failure actions” that can be added beneath it,  which would be executed in your failure branch.  The actions you added below the snippet action become your success branch… 

A little bit of coding,  but not a problem.