Stop updataRow() from calling its own change event?

I have this function within a custom component to handle changes. I want to run updateRow() within the function, but I end up with a loop that runs several times before mysteriously quitting.

Does a function have an initiatorId? Or is there anythingother way to tell the function not to repeat itself after it calls updateRow()?

// Define a function to handle change.&nbsp; &nbsp; &nbsp; &nbsp; <br>component.change = function(){<br>&nbsp; &nbsp;console.log('CHANGE');<br>&nbsp; &nbsp; // Do some other stuff...<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Update Name and Date<br>var sigName = signatureModel.getFieldValue(signatureRow,'Signature_Name__c') || (defaultName == 'Custom') ? customDefaultName : defaultName;<br>&nbsp; &nbsp; &nbsp; &nbsp; <b>signatureModel.updateRow(<br></b><b>&nbsp; &nbsp; signatureRow,<br></b><b>&nbsp; &nbsp; {<br></b><b>&nbsp; &nbsp; &nbsp; Signature_Name__c: &nbsp;sigName,<br></b><b>&nbsp; &nbsp; &nbsp; Signature_Date__c: &nbsp;skuid.time.getSFDateTime(new Date())<br></b><b>&nbsp; &nbsp; },<br></b><b>&nbsp; &nbsp; {initiatorId: this._GUID} </b><b>);</b><br>return component;<br>}

How is component.change being fired? Are you listening to the row.updated event from the api? If so, you could probably filter it down to only listen to changes to certain fields, not all fields.

component.change is handling changes for the editor:

component.editor.handleChange = component.change;

Try adding a parameter to your change function and logging that.  It might have some info that you could use.

component.change = function(changeinfo){

&nbsp; &nbsp;console.log('CHANGE'); console.log(changeinfo);

Here’s what I get.

It looks like you’re not getting any loop at all, just that there are 3 times where that row is updated in your component.

Sorry, that was a bad example… I had a different error in my code so it wasn’t functioning properly.

Here’s a better example:

The first CHANGE is called (as it should be) when I make a change in jsignature.
The second CHANGE is called because of the updateData within the first CHANGE.

I was thinking that I didn’t need that second CHANGE. but perhaps I do?

Yeah, I’m saying you can add an additional if statement around your updateRow call. Only updateRow if changeinfo.SignatureData__c != null. That way you won’t get the possibility of an infinite loop.

Right. That makes sense.

Interestingly, when I pause the code and step through it in the console, CHANGE repeats infinitely. Everytime it runs updateRow() it immediately starts component.change() again. But when I just let it run by itself, it only runs component.change() once for each set of changes.

Yeah, I know why that is. updateRow has some checks in it to prevent infinite loops. If you send in the exact same “payload” to updateRow, it will not update, or call any of its handlers. In your case, you’re sending in the current date. So when you slowly iterate through using a debugger, it gets a different date each time. (Because it might be a second or millisecond off). But when you do it without the debugger, Javascript executes so fast that updateRow gets the exact same “payload” and refuses to notify its handlers.


Still, worth a few extra lines of code to explicitly prevent the loop.

Thanks again, Ben. Got it working.