Field auto update

akin9
Tera Contributor

Hello experts,

We have created a button "inactive aset" in "alm_hardware" table and confrmation

pop up also with Ok and  cancel.  its working fine.

akin9_0-1710265845200.png

Requirement

1.If user clicks ok then some of the field values needs to change automatically

on the "alm_asset" table  like below.

2.This button need to visible for only "smartphone" and "computer" category only.

 

comments

Add comment:

1) Retired on >Date< by >User<.

2) Automatically retired on >Date< by System.

install_status

Retired -> ‘7’

 

I have tried with after insert BR for update fields. but no luck ,can you pls support!

any other approach 

 

 

1 ACCEPTED SOLUTION

Try this

function doRetire(){

	if(confirm('Are you sure?'))
	{
		gsftSubmit(null, g_form.getFormElement(), 'inactive_device');
	}
}

if(typeof window == 'undefined')
retireDevice();

function retireDevice(){
	current.setValue('install_status', 7);
	current.update();
}

View solution in original post

11 REPLIES 11

Abdullah12
Tera Expert

If you want to update records of same table on which you are using after business rule then you need to use:
current.setWorkflow(false);
current.update();

For more information : read the following thread especially [Prevent Recursive Business Rule] heading.
https://www.servicenow.com/community/developer-forum/updating-records-with-after-business-rules/m-p/...


If my response is helpful mark is as helpful or correct. Thankyou

James Chun
Kilo Patron

Hey @akin9,

 

1. You can run both client and server scripts within a UI Action. Refer to the article below and give it a go
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1005843

 

2. Add some script in the 'Condition' field such as 
current.getValue('category') == 'smartphone' || current.getValue('category') == 'computer' 

 

Cheers

akin9
Tera Contributor

Hello @James Chun ,

Thanks for the quick reply!

I have tried that but no luck i want to upfate fields on "alm_asset" like below

install_status

Retired -> ‘7’

can you please help me on the script.

akin9_0-1710271589400.png

 

Try this

function doRetire(){

	if(confirm('Are you sure?'))
	{
		gsftSubmit(null, g_form.getFormElement(), 'inactive_device');
	}
}

if(typeof window == 'undefined')
retireDevice();

function retireDevice(){
	current.setValue('install_status', 7);
	current.update();
}