Field values set in snippet are not getting saved either by save method or by button action

  • 1
  • Problem
  • Updated 7 months ago
  • In Progress
Hi,

I have a table mass action which opens a popup. In the popup,  I have a button which calls a snippet to update few fields on the selected rows. I am using save() method to save the model rows. Once saved, I am closing the popup but the problem is that save is not happening. I can see the unsaved fields with updated values after popup is closed.
I even tried to remove the same method from snippet and add it as an action but that too did not work. I do not see any error in console. Any help is appreciated.
Photo of Shalabh Sharma

Shalabh Sharma

  • 294 Points 250 badge 2x thumb

Posted 7 months ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Shalabh,

Would you share your snippet and the XML of your model.

One thing that may be affecting you is that the line to close the popup may be running before your save completes.  You can try wrapping your 'close' in a promise:
var model=skuid.model.map().NameOfModel;
$.when(model.save())
.done(function(){
console.log('Models Saved'); //close all popups skuid.$('.ui-dialog-content').dialog('close');
})

Thanks,

Bill
Photo of Shalabh Sharma

Shalabh Sharma

  • 294 Points 250 badge 2x thumb
Bill,

I tried what you suggested but it did not help. I got the log "Models Saved" in console but record was still unsaved.
Here is my snippet:

var table = skuid.$C('approverTable'),
    list = table.element.data('object').list;
var $ = skuid.$,
    ApprovalHistory = skuid.model.getModel("ApprovalHistory"),
    selectedItems = list.getSelectedItems(),
    rowsToUpdate = {};
    $.each( selectedItems,
    function( i, item )
    {
        var row = item.row;
        rowsToUpdate[ row.Id ] = {Approval_Status__c:'Pending Approval'};
    });
    ApprovalHistory.updateRows(rowsToUpdate);
    $.each( ApprovalHistory.data,
    function( i, row )
    {
        if(ApprovalHistory.getFieldValue(row,'Approval_Status__c')===null){
            rowsToUpdate[ row.Id ] = {Approval_Status__c:'Consulted'};
        }
    });
    ApprovalHistory.updateRows(rowsToUpdate);
    $.when(ApprovalHistory.save())
    .done(function(){
    console.log('Models Saved');
    //close all popups
    skuid.$('.ui-dialog-content').dialog('close')});




Here is the model xml:

<model id="Approvers" limit="50" query="false" createrowifnonefound="false" datasource="salesforce" type="" sobject="Contact">
            <fields>
                <field id="RecordTypeId"/>
                <field id="AccountId"/>
                <field id="Account.Name"/>
                <field id="MailingCity"/>
                <field id="Id"/>
                <field id="MailingCountry"/>
                <field id="Email"/>
                <field id="Name"/>
                <field id="Role__c"/>
                <field id="Title"/>
                <field id="FirstName"/>
                <field id="LastName"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="AccountId" fieldtargetobjects="Account" operator="=" model="Project" enclosevalueinquotes="true" mergefield="Account__c" novaluebehavior="deactivate"/>
                <condition type="fieldvalue" value="Client" enclosevalueinquotes="true" field="RecordType.Name" state=""/>
                <condition type="fieldvalue" value="Approver" enclosevalueinquotes="true" field="Role__c"/>
            </conditions>
            <actions/>
        </model>
        <model id="ApprovalHistory" limit="20" query="false" createrowifnonefound="false" datasource="salesforce" type="" sobject="Approval__c" orderby="CreatedDate DESC">
            <fields>
                <field id="Approval_Status__c"/>
                <field id="Approver_Comments__c"/>
                <field id="Approver_Email__c"/>
                <field id="Approver__c"/>
                <field id="Approver__r.Name"/>
                <field id="Approval_Date__c"/>
                <field id="Project__c"/>
                <field id="Project__r.Name"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="Project__c" fieldtargetobjects="Project__c" operator="=" model="Project" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/>
            </conditions>
            <actions/>
        </model>
(Edited)
Photo of Shalabh Sharma

Shalabh Sharma

  • 294 Points 250 badge 2x thumb
Can someone please help me with this issue?
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Shalabh,

I don't see any problems with your code.  I did notice that your ApprovalHistory model does not include the 'Id' field.  I don't think this is needed, but its an easy addition to see if it resolves your issue.

What version of Skuid do you have installed?

Thanks,

Bill