- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 01:20 AM
Hi experts,
We have requirement to capture what all stages the state field has gone through in a custom field.
Please suggest what should be the Custom field type? should be a list field or string?
How can we achieve this.
Thanks inadvance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 01:47 AM
Hi @rajasekar reddy ,
You can Create string field with maximum limit as 400-500
Write below BR : I'm writing on incident table
Condition State changes
Before update/Insert
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var PrevValue=current.u_comments; //Change u_comment with your string field
current.u_comments=PrevValue+"\n"+current.getDisplayValue('state'); //Change u_comment with your string field
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 01:40 AM
Have a string field and make it as readonly
Write a br when ever state changes after update
var val = current.getValue('u_new_field');
if(val ==""){
current.setValue( "state chnage from "+previous.getValue(state)+" to"+current.getValue("state"));
}
else{
current.setValue('u_new _field', val+"," + "state chnage from "+previous.getValue(state)+" to"+current.getValue("state"));
}
your output will be if new string field is empty and state change from new to inprogress
"State changes from new to inprogress"
our output if new string field has alredy some value in it and sttae change from in progress to resolved
"State changes from new to inprogress, State changes from inprogress to resolved"
One drawback is it cannot be used for reporting purpose
if it helps
Mark as helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 01:47 AM
Hi @rajasekar reddy ,
You can Create string field with maximum limit as 400-500
Write below BR : I'm writing on incident table
Condition State changes
Before update/Insert
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var PrevValue=current.u_comments; //Change u_comment with your string field
current.u_comments=PrevValue+"\n"+current.getDisplayValue('state'); //Change u_comment with your string field
})(current, previous);
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:12 AM
Hello @rajasekar reddy ,
So do you want to store it for future purpose also?
First approach i would suggest it use journal fields to capture the state changes .
When ever there is a state change your change will be captured in activities
see below screenshot and go to filter icon and select state field and try to change the state you will see the change captured in the activity logs
OR
Lets say the state changed from new to in progress and from in progress to closed.
So you can go for string field for this where in that new field you can append the state transitions using a BR on your table.
BR should be after update
condition : state changes
then you script can be like below
var gr = new GlideRecord('your_table_name');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
gr.new_field_name = gr.new_field_name+ "state changed from "+previous.getValue(state)+" to"+current.getValue("state") + "\n";
gr.update();
}
Hope this helps
Mark my answer correct if this helps you
Thanks