Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

akin9
Tera Contributor

Hello @James Chun ,

Thanks above code is working!

but i want to show the button for two categories only i have added on the condition but 

now button is not visible.

current.getValue('model_category') == 'Smartphone' || current.getValue('model_category') == 'Smartphones_Insight'

akin9_0-1710274129357.png

 

Hi @akin9,

 

Are you sure you are using the right value? Maybe it's 'smartphone' not 'Smartphone'?

Sorry, just realized it's a reference field.

 

You can either use the 'sys_id' of the Model categories or use its display name.

i.e. current.model_category.name.toString() == 'Smartphone'

akin9
Tera Contributor

Hi @James Chun ,

Thanks its category is working but one of the field operational status and "lifecycle" fields not able to update. pls correct me!

function doRetire(){

	if(confirm('Are you sure want to inactive this device?'))
	{
		gsftSubmit(null, g_form.getFormElement(), 'inactive_device');
	}
}

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

function retireDevice(){
	current.setValue('install_status', 7);
	current.setValue('substatus','disposed');
	current.setValue('life_cycle_stage','End of Life');
	current.setValue('life_cycle_stage_status','Retired');
	current.setValue('operational_status','Decommissioned');
	current.comments = 'Automatically retired on ' + new Date() + ' by System'; current.install_status = '7';

	current.update();
}

akin9_0-1710275425011.png

 

Hi @akin9,

 

I believe the life_cycle_stage and life_cycle_stage_status are both reference types, not a string type.

And I am not sure whether it's recommended to update the life cycle stage & life cycle stage status in this way. It may break/interfere with other OOB processes. Unfortunately, I can't comment too much on this.

 

Cheers