Flow Designer to dynamically update the field that was entered as the action input

jonathangilbert
Kilo Sage

Hi All

 

Can someone please help me with my Flow designer action script below which is to update a field value based on the field name entered as the "field" input .update record script.png

 

(function execute(inputs, outputs) {
var user = new GlideRecord(inputs.tablename);
var field = inputs.field;
user.addQuery('sys_id',inputs.sys_id1);
user.query();
while(user.next()){
 user(inputs.field) = inputs.value;//script should update the field that was entered as the input .ie "u_accident"
 user.update();
}})(inputs, outputs);
 
 

My use case is that I have a record producer and the variables are mapped to the record fields. If the value on the record is changed, then Flow designer correctly updates the associated variable.

 

I want  the ability that if the variable is changed, then it updates the mapped field. I have created a flow that looks up the mapped field of the variable question, which will then return the field name i,.e "u_accident".

This field name is then one of the inputs on my script called "field". I then want the script to be able to update that field on the record, but my script is not able to recognise:-

user(inputs.field) = inputs.value;
 
If it was a stactic line of script it would be:-
user.u_accident = inputs.value;    (which works perfectly)
 
 
Any help would be much appreciated 🙂
Thankyou all
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jonathangilbert 

try this syntax

user[inputs.field] = inputs.value;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@jonathangilbert 

try this syntax

user[inputs.field] = inputs.value;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

t_sadahisa
Giga Guru

@jonathangilbert 

Please try following scripts.

 

(function execute(inputs, outputs) {
var user = new GlideRecord(inputs.tablename);

user.addQuery('sys_id',inputs.sys_id1);
user.query();
while(user.next()){
 user.setValue(inputs.field) = inputs.value;//script should update the field that was entered as the input .ie "u_accident"
 user.update();
}})(inputs, outputs);