Comments on: Checking for Modified or Changed Fields in Script https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/ ServiceNow Consulting Scripting Administration Development Thu, 07 Mar 2024 16:49:33 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Ayush Saxena https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8103 Mon, 11 Feb 2019 21:47:32 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8103 In reply to Ayush Saxena.

Quick question is there a way to post changes made on other table. I mean if value of alert record changes, I want to log those changes on incident table in work notes.I guess var gru = GlideScriptRecordUtil.get(gr); is not supported.

Answer : I was able to pass it as string to Incident and later parse it.

Thanks Mark for the above post !! :)

]]>
By: Ayush Saxena https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8102 Mon, 11 Feb 2019 17:00:47 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8102 Great Stuff Mark !!

I was getting value as undefined when I pasted below script, I guess the val is already comprising of value of the field. I removed .getDisplayValue() from gs.addInfoMessage(changedFields[i] + ‘: ‘ + val.getDisplayValue()); and it worked like a charm.

//Display an information message for each change to the record
var gru = GlideScriptRecordUtil.get(current);
var changedFields = gru.getChangedFields(); //Get changed fields with friendly names
var changedValues = gru.getChanges(); //Get changed field values
//Convert to JavaScript Arrays
gs.include(‘j2js’);
changedFields = j2js(changedFields);
changedValues = j2js(changedValues);

//Process the changed fields
for(var i = 0; i < changedValues.length; i++){
var val = changedValues[i];
if(val.getED().getType() == -1 && val.getJournalEntry(1)){
//Print out last journal entry for journal fields
gs.addInfoMessage(val.getJournalEntry(1));
}
else{
//Print out changed field and value for everything else
gs.addInfoMessage(changedFields[i] + ': ' + val.getDisplayValue());
}
}

Quick question is there a way to post changes made on other table. I mean if value of alert record changes, I want to log those changes on incident table in work notes.I guess var gru = GlideScriptRecordUtil.get(gr); is not supported.

]]>
By: Colleen Bester https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8100 Fri, 10 Nov 2017 22:22:24 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8100 I don’t know if anyone is going to still be looking at this. But, just in case, it looks like you can get the old values with some coding, using the previous item. Basically, if you use gru.getChangedFieldNames() in a business rule, and then use previous.getValue() with the fieldname that was changed, you can get the old value.

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8099 Thu, 03 Mar 2016 14:51:32 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8099 In reply to Stijn Van Echelpoel.

Good question. There’s not a way I’ve built yet but I’ve addressed this in the top comment on this thread from Brian Broadhurst. It offers a couple of suggestions for how you could do this. Not as straight-forward as it should be unfortunately.

]]>
By: Stijn Van Echelpoel https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8098 Thu, 03 Mar 2016 13:57:28 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8098 Hi Mark,

Thank you for the quick reply. My business client has one additional question concerning the notification. Is it possible to show both the current and previous value of the fields that have been changed in the notification mail?

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8097 Wed, 02 Mar 2016 09:40:41 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8097 In reply to Stijn Van Echelpoel.

Yes, you would need to include an ‘if’ statement to check to see that the field name matched what you wanted to include (or exclude). In the mail script example, the ‘if’ statement would need to start directly below the ‘var field’ line and wrap around everything up-to and including the final ‘else’ statement. if(field == ‘category’ || field == ‘short_description’) would allow for just the category or short description fields for example.

]]>
By: Stijn Van Echelpoel https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8096 Wed, 02 Mar 2016 09:33:02 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8096 Mark,

Thank you very much for sharing your code. It is extremely useful.
I am particullary interested in the section about “Printing all record changes in an email notification”.

I am very interested in using these code snippets but when notifying users they are not interested in all variables. For example they don’t need information about system variables.
My question is can I limit the number variables displayed in my notification to a selection of my choice?

How would I acieve that ? I suppose with somekind of IF structure.

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8095 Wed, 20 Jan 2016 16:59:07 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8095 In reply to Jose Eduardo Chirinos Odio.

You can try ‘GlideRecordScriptUtil’ instead. That’s the new class name as of Calgary. I am seeing that ‘getChanges()’ is broken in Geneva even though it’s still available as a method. I’d advise you to contact ServiceNow support about that one.

]]>
By: Jose Eduardo Chirinos Odio https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8094 Wed, 20 Jan 2016 16:03:47 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8094 Hello Mark Stanger and everyone else, I was checking out this code in Geneva Release, this is my output of the business rule: if it is tested in global scope the script indeed recognizes the changes made to a form, the only thing that was not working is “what is the new data added”, I get an undifined in the info message, something like this: “Short_description : undefined”, I am just letting you all know! :)

Now that I shared my output of this script in Geneva, I would like to request some help! I trying to do this but in a scoped application! :), what I recieved at first instance was that GlideRecordUtil is not available for scoped applications, so I used the word ‘global’ before each statement related to GlideRecordUtil, and it almost worked!! then the output I keep recieving this:

‘Invalid object in scoped script: [JavaClass com.glide.script.GlideRecordUtil]’

I have tried so hard to make this right! and it was not possible! any ideas? how to apply the same scrip to a scoped application!? :) Thank you very much in advance! very good post!

]]>
By: Michael McCall https://servicenowguru.com/client-scripts-scripting/checking-modified-fields-script/#comment-8093 Thu, 21 May 2015 22:35:15 +0000 https://servicenowguru.wpengine.com/?p=3175#comment-8093 Is there a simple swap for g_form.getControl() that allows you to discover value changes on mobile forms? I’m building a Client Script to check if specific fields have new values before submitting, and getControl() is perfect…

…except for the new deprecation warnings on the Wiki! (http://wiki.servicenow.com/index.php?title=Mobile_Client_GlideForm_%28g_form%29_Scripting#Do_Not_Use_Deprecated_Methods)

Is this type of logic just something that can’t be easily achieved in mobile? (By the way, I’m specifically checking in a Client Script because I’m prompting users with a chance to cancel their submission when certain fields are changed.)

]]>