- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2021 01:29 AM
Hi ,
I am trying to create an UI action to update only one field. I tried using the below code
function saveDesc() {
var desc = g_form.getValue('description');
g_form.setValue('description', desc);
gsftSubmit(null, g_form.getFormElement(), 'save_dec');
action.setRedirectURL(current);
}
Action Name : save_dec
I am bale to save if i added the value of the description in the setvalue method. But if I am trying to get and set it is not working as expected. and after this script the page should be redirected to the same form page.
Can someone help me out.
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2021 10:35 PM
I got the solution,
Instead looking for client side solution we can do it via server scripting via GlideRecord.
current.update is updating all the fields. so using below code we can get the solution.
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',current.sys_id);
gr.query();
while(gr.next()) {
gr.description = current.description;
gr.update();
}
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2021 01:45 AM
Hi , Try this in your UI Action code
function saveDesc() {
var desc = g_form.getValue('description');
g_form.setValue('description', desc);
gsftSubmit(null, g_form.getFormElement(), 'save_dec');
}
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
current.update();
gs.addInfoMessage('You did it!'); //testing
action.setRedirectURL(current);
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2021 02:02 AM
You should verify if any of the values in form are modified or not, if yes then clear the value.
check below links
https://servicenowguru.com/scripting/business-rules-scripting/checking-modified-fields-script/
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-08-2021 10:35 PM
I got the solution,
Instead looking for client side solution we can do it via server scripting via GlideRecord.
current.update is updating all the fields. so using below code we can get the solution.
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',current.sys_id);
gr.query();
while(gr.next()) {
gr.description = current.description;
gr.update();
}
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-30-2022 06:15 AM
this is not working with Additional Comments (Journal Input) type field on my form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-30-2022 06:16 AM
I want to update Additional Comments field only with current additional comments field value