Unable to perform field update in snippet

  • 1
  • Problem
  • Updated 3 years ago
Hi,

We have field renderer on opportunity's status field. in opportunity data table, if user updates status to declined, we need to show popup with additional fields and also, map send notification field to closedate.

popup is created and everythin works well with the exception of notification date being saved to database. here is the popup creation code:
var context = arguments[0];if(context.row.StageName=='Declined'){
    if(context.row.Send_Decline_Notification__c === null || context.row.Send_Decline_Notification__c === undefined) {
        var ManagersView_NewBusinessModel = skuid.model.getModel('ManagersView_NewBusiness');
        var varContextRow = ManagersView_NewBusinessModel.getRowById(context.row.Id);
        ManagersView_NewBusinessModel.updateRow(varContextRow,'Send_Decline_Notification__c',context.row.CloseDate);
    }
    console.log(context.row);
//SHOWS VALUE BEING MAPPED TO Send_Decline_Notification__c
    console.log(ManagersView_NewBusinessModel.getRowById(context.row.Id));
var popupXMLString = 
'<popup title="Update Submission" width="90%">'
+'<components>'
  +'<pagetitle model="ManagersView_NewBusiness">'
+ '<conditions>'
                + '<condition type="contextrow" field="Id" mergefield="Id"/>'
          + '</conditions>'
 +'<actions>'
+'<action type="multi" label="Save" icon="sk-icon-save">'
+'<actions>'
  +'<action type="blockUI"/>'
  +'<action type="custom" snippet="SaveOpportunityComments"/>'
  
  +'<action type="save" rollbackonanyerror="true">'
 +'<models>'
+'<model>ManagersView_NewBusiness</model>'
 +'</models>'
 +'<onerroractions/>'
  +'</action>'
  
  +'<action type="requeryModel" model="ManagersView_NewBusiness" behavior="standard"/>'
  +'<action type="unblockUI"/>'
  +'<action type="emptyModelData"><models><model>SubmissionComments</model></models> </action>'
  +'<action type="closeAllPopups"/>'
+'</actions>'
+'</action>'
+'<action type="multi" label="Cancel" icon="sk-icon-cancel">'
+'<actions>'
+'<action type="blockUI"/>'
+' <action type="cancel"><models><model>ManagersView_NewBusiness</model> </models></action>'
   +'<action type="requeryModel" model="ManagersView_NewBusiness" behavior="standard"/>'
    +'<action type="unblockUI"/>'
  +'<action type="closeAllPopups"/>'
  
+'</actions>'
+'</action>'
 +'</actions>'
  +'</pagetitle>'
  +'<basicfieldeditor showheader="true" showsavecancel="false" model="ManagersView_NewBusiness" buttonposition="" mode="edit" layout="">'
 +'<columns>'
+'<column width="100%">'
+'<sections>'
  +'<section title="Section A" collapsible="no" showheader="false">'
 +'<fields>'
+'<field id="StageName" valuehalign="" type=""/>'
+ '<field id="eStart_Status_Reason__c">'
                         + '<label>Status Reason</label>'
                         + '</field>'
+'<field id="Send_Decline_Notification__c" valuehalign="" type=""/>'
+'<field id="Comments__c" valuehalign="" type=""/>'
 +'</fields>'
  +'</section>'
+'</sections>'
+'</column>'
 +'</columns>'
  +'</basicfieldeditor>'
+'</components>'
+'</popup>';
var popupXML = skuid.utils.makeXMLDoc(popupXMLString);
var popup = skuid.utils.createPopupFromPopupXML(popupXML,context);
}

i have tried to set field value in different ways but it doesn't work. even though on page popup, value is assigned to field but when it is saved, field is still blank.

any help will be appreciated.

thanks.
Photo of Sunny Sharma

Sunny Sharma

  • 678 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I think that the action you are describing is in the snippet "SaveOpportunityComments"  you don't show that snippet here.  This is where I'd look.  Its probably where you are trying to grab the current date and save it as close date.  Put console log statements in that snippet and see if you can see what is oging on. 

You can also popuplate a date field with TODAY using the action framework.  
Photo of Sunny Sharma

Sunny Sharma

  • 678 Points 500 badge 2x thumb
hi Rob

we are assigning opportunity's close date to opportunity send decline notification date field if and only if notification date is blank. 

here is the other snippet. in this snippet, value is displayed in console but not saved to database.:
var params = arguments[0], $ = skuid.$;

var opportunityModel = params.row;
console.log("opportunityModel " + opportunityModel.Send_Decline_Notification__c);
if(opportunityModel.Comments__c !== undefined && opportunityModel.Comments__c !== null && opportunityModel.Comments__c !== '') {
    var SubmissionCommentsModel = skuid.$M('SubmissionComments');
        SubmissionCommentsModel.createRow({
            additionalConditions:[    
                {field : 'Target_Submission__c', value : opportunityModel.Id},
                {field : 'Comments__c', value:opportunityModel.Comments__c }
        ],doAppend: true
        }); 
        SubmissionCommentsModel.save({callback: function(result){
            }});
}
Photo of Sunny Sharma

Sunny Sharma

  • 678 Points 500 badge 2x thumb
not sure what happened but thankfully this is working now.
still wondering what change i made that it worked.
:D

thanks Rob for your help.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
That is both the best and the worst kind of solution.  Nice that its fixed. Worrysome that you don't exactly know how it got fixed...