- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2020 05:48 AM
I need code for changing state value while click on state inprogress button which is created on incident form
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2020 06:01 PM
Hi Gopi,
Type UI Action in left navigator and Select System Definition > UI Actions
Click New
Name - In Progress
Table - Incident
Form Button - Checked
Script
(function(){
current.state = 2; // set the opened incident state to in progress
current.update(); // update the opened incident to save the changed state
gs.setRedirectUrl(current); //redirect back to open incident.
})();
Screenshot for reference
Please mark this accepted & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2020 06:01 PM
Hi Gopi,
Type UI Action in left navigator and Select System Definition > UI Actions
Click New
Name - In Progress
Table - Incident
Form Button - Checked
Script
(function(){
current.state = 2; // set the opened incident state to in progress
current.update(); // update the opened incident to save the changed state
gs.setRedirectUrl(current); //redirect back to open incident.
})();
Screenshot for reference
Please mark this accepted & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2020 07:50 PM
If you need to do it in real-time (to trigger UI Policy or Client Scripts for mandatory fields etc) it would be as follows:
Client = checked
Callable script:
setStateToInProgress
Script
function setStateToInProgress() {
var inProgressValue = 2;
g_form.setValue('state',inProgressValue );
g_form.save(); // Let the UI Policies and client scripts do the work
}
I find doing it this way (rather than Server-side) makes for a better UX.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2021 03:27 PM