Auto update column in Incident table

Kalpesh Kalgutk
Tera Contributor

Hi,

 

I would like to write a script to update a column when a specific subcategory is selected in Incident table.

 

Could you please assist me with this?

 

Thank you.

2 ACCEPTED SOLUTIONS

Hello @Kalpesh Kalgutk ,

You can put below line of code in your Business Rule -> 

 

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var session = gs.getSession();
var URL = session.getUrlOnStack();
//gs.info(URL);
current.COLUMN_NAME = URL;

})(current, previous);

 

Reference documentation - https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/c_GlideSessionScopedAPI

 

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

View solution in original post

Hello @Kalpesh Kalgutk ,

I see & understand what is implemented. If interested, you can try my solution so provided in your PDI and we can check why it does not work. Normally, it does.

 

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

View solution in original post

11 REPLIES 11

Zach Koch
Giga Sage
Giga Sage

Depends on whether you need this as a Business rule or as a client script. If you need more specific guidance, you'll need to provide more detail on your business requirement.

 

BR would look something like this

Your condition would be

Subcategory is <yourValue>

and you could use the set value section to set your desired value in your desired column, all without code.

 

In a onChange client script, it would look something like this

 

if(newValue == <yourSubcategory>) {
g_form.setValue('yourField', 'desiredValue');
}

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Hi Zach,

 

Thank you. I believe a Business Rule would be a good option. I want to add a link in the column that includes the current incident number after the incident is created, like this example: www.google.com=INC123.

 

Regards,

ShubhamGarg
Kilo Sage

Hello @Kalpesh Kalgutk ,

->If requirement is about auto-populating a value (client side) of one column if value of another column is selected, then, it is good to go for client side scripting like onChange Client Script.

->If requirement is about setting/saving a value (server side) of one column if value of another column is selected, then, it is good to go for server side scripting like Business Rule, script action, etc.

 

To answer specifically on your question, I would need to elaborate a bit more about your scenario.

 

If my response helps you in any way, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Regards,

Shubham

Hi Shubham,

 

Thank you. I believe a Business Rule would be a good option. I want to add a link in the column that includes the current incident number after the incident is created, like this example: www.google.com=INC123.