Skip to main content

I’m working from this post that describes how to create a custom renderer on a formula that listens for changes to the input fields.  I have a very similar use case, but am using a Date/Time field and suspect I am getting tripped up on the translation from Salesforce Date/Time format to Javascript Date/Time and back.  

When I use the custom renderer, nothing happens.  My formula field continues to display its existing value until I save.

Here’s my snippet:


var FIELDS_TO_LISTEN_ON = T‘Nurse_Intake_Time_Patient_Time_Zone__c’];
var field = argumentsd0],
     value = argumentsa1],
     row = field.row,
     listener;

skuid.ui.fieldRenderers.DATETIMEfield.mode;

// Register a listener so that if any of FIELDS_TO_LISTEN_ON are updated,
// then we will update ourself as well.

if (!listener) {
   
   listener = new skuid.ui.Field(row,field.model,null,{register:false});

   var calcNewValue = function(){

       var  value0 = row.Nurse_Intake_Time_Patient_Time_Zone__c || 0,
              value1 = skuid.time.parseSFDateTime(value0),
              value2 = row.Nurse_Assignment__r.UTC_Offset__c || 0,
              value3 = row.Account.tz__UTF_Offset__c || 0,        
        
        newValue0 = value1 + (value2/24 - value3/24);
        newValue=skuid.time.getSFDateTime(newValue0);
       
       field.model.updateRow(row,‘Nurse_Intake_Time_Patient_Time_Zone__c’,newValue);

       field.element.empty();
       skuid.ui.fieldRenderers.DATETIME.readonly(field,newValue);
       
   }
   
    listener.handleChange = function(){calcNewValue (); };
    listener.render = function() {};

   skuid.$.each(FIELDS_TO_LISTEN_ON,function(i,fieldToRegisterOn){
       field.model.registerField(listener,fieldToRegisterOn);
   });

   setTimeout(function(){
       // If there is already a changes row for this item,
       // then run calculation
       if (field.model.changestfield.row.Id]) {
             calcNewValue ();
       }
   },100);

}

Be the first to reply!

Reply