How to clear field by background script

Ereshkigal
Tera Contributor

Hi.

I want to empty the values ​​of the "client_id" and "client_secret" fields in the oauth_entry table after saving.

I want to execute the process only for a specific record, so I wrote the process in the Background Script and executed it, but it didn't work.

I will write the script below, but if there is something missing, could you please tell me?

BackgroundScript:

var test = new GlideRecord("oauth_entity");
	test.addQuery("sys_id", "f7529bae87c0511006738517cebb3514");
	test.query();
	
	if(test.next()){
		test.setValue("client_id", "");
		test.setValue("client_secret", "");
	}

Thank you!

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Try the below script, Your not updating the record in the script

 

var test = new GlideRecord("oauth_entity");
test.addQuery("sys_id", "f7529bae87c0511006738517cebb3514");
test.query();

if(test.next()){
test.setValue("client_id", "");
test.setValue("client_secret", "");
test.setWorkflow(false); //Do not run business rules
test.autoSysFields(false); //Do not update system field
test.update();
}

Regards
Harish

View solution in original post

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Try the below script, Your not updating the record in the script

 

var test = new GlideRecord("oauth_entity");
test.addQuery("sys_id", "f7529bae87c0511006738517cebb3514");
test.query();

if(test.next()){
test.setValue("client_id", "");
test.setValue("client_secret", "");
test.setWorkflow(false); //Do not run business rules
test.autoSysFields(false); //Do not update system field
test.update();
}

Regards
Harish

Thank you. Thanks to you, I was able to remove the value of Client ID.

One thing I would like to confirm is that the value of Client Secret is not empty, and it is encrypted because the type is "Password (2 Way Encrypted)" and the value is actually deleted. Is not it.

find_real_file.png