current.setvalue

Sneha39
Mega Guru

Table = u_test_table

Fields = field1, field2 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e2132865c0a8016500108d9cee411699');
var rc = cart.placeOrder(); 
var number = rc.number
//i want to set rc.number in field1 (BR on table u_test_table)
current.setValue(field1,number) ---- this is not working neither
1 ACCEPTED SOLUTION

Hi Neha,

your BR has different field name

current.setValue('u_field1',number);
current.update();

Regards
Ankur

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

View solution in original post

10 REPLIES 10

Hi Neha,

Is the field name correct i.e. field1?

Is this before BR?

Regards
Ankur

 

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

after BR, yes field name is correct

Hi Neha,

since it is after update BR you would require to use current.update()

Is field1 a string or reference?

if it is string then use this

current.setValue('field1',number);
current.update();

if it is reference to RITM then use this

current.setValue('field1',rc.getUniqueValue());
current.update();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

Alok Das
Tera Guru

Hi Neha,

If the field type is reference and it's referencing sc_request table then you need to set the sys_id of the field instead of number, use the code to set the value of field rc.getUniqueValue();.

Also, it seems like field1 is the column label not the column name since it's a custom field it might be starting from u_, I request you to navigate to the dictionary and check for the correct field column name. I believe it would be u_field1.

Could you please give a try with below script if the field1 is a string field:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e2132865c0a8016500108d9cee411699');
var rc = cart.placeOrder(); 
var number = rc.number.toString();
//i want to set rc.number in field1 (BR on table u_test_table)
current.setValue('u_field1',number);

OR please give a try with below script if the field is a reference field referencing sc_request table:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e2132865c0a8016500108d9cee411699');
var rc = cart.placeOrder(); 
var number = rc.getUniqueValue();
//i want to set rc.number in field1 (BR on table u_test_table)
current.setValue('u_field1',number);

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok

Tried both its not working with rc.number it was returning request number with .toString its return into string but its not setting the valur in u_field1