So I’ve been trying to use the “row.updated” event to stop users from entering a certain combination of fields. It’s working great but I’m also trying to update the field back to the previous value. I’m running into problems with the snippet getting looped and running forever. When I do a simple update to a picklist field it works fine, but when I update a reference field it keeps running forever. I tried using the “initiatorId” to indicate what caused the update, but that doesn’t seem to help. My code looks like this, as an inline snippet:
(function(skuid){ var $ = skuid.$;
$(function(){
//reverse the changes that were made to keep the user from saving the bad combination of data
function reverseUpdate(updateResult){
console.log(updateResult);
var model = skuid.$M(updateResult.modelId);
if(updateResult.updates.Bill_Type__c){
model.updateRow(updateResult.row,‘Bill_Type__c’,‘Dual Bill’,{
initiatorId: updateResult.initiatorId
});
}else if(updateResult.updates.Pricing_Product__c){
var fixed = skuid.$M(‘Fixed’);
var fixedRow = fixed.getFirstRow();
//could this be causing everything to break because it’s an update to a reference field?
model.updateRow(updateResult.row,‘Pricing_Product__c’,fixedRow.Id,{
initiatorId: updateResult.initiatorId
});
}
}
skuid.events.subscribe(‘row.updated’,function(updateResult){
if(updateResult.modelId === ‘Tenors’){
var commodityName = skuid.$M(‘Opportunity’).getFirstRow().Commodity__r.Name;
var countOfRateReadyLDC = 0;
$.each(skuid.$M(‘IntakeQueues’).data, function(i,rowIQ){
countOfRateReadyLDC += rowIQ.LDC__r.LDC_LDC__c;
});
var hasSingleBill = false;
var hasLBMP = false;
if(updateResult.row.Bill_Type__c === ‘Single Bill’) hasSingleBill = true;
if(updateResult.row.Pricing_Product__r.Name === ‘LBMP+’) hasLBMP = true;
if(hasLBMP && hasSingleBill && (countOfRateReadyLDC > 0) && (commodityName === ‘Electricity’)){
var pageTitle = $(‘#MyPageTitle’);
var editor = pageTitle.data(‘object’).editor;
editor.handleMessages([{message:‘Sorry! Electric, Indexed, Single Bill deals are not allowed when an LDC is Rate Ready.’, severity:‘ERROR’}]);
reverseUpdate(updateResult);
}
}
});
});
})(skuid);
Question
Subscribe to event, but only run once
This topic has been closed for replies.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.