Update requested item variables using REST API

Eli Guttman
Tera Guru

Hi,

Does anyone know if it is possible to update requested items variables using REST API?

I tried it using the REST API Explorer, directly on the sc_req_item table with this body:

========

{"variables.person_name":"Eli"}

=======

i was able to update a field, but not the variables.

thank you!

1 ACCEPTED SOLUTION

Hi Eli,



Create a Scripted REST API and resource as PUT.


Have some sample json incoming request such as below:


{


  "ritm": "RITM0001",


  "variables": {


      "user": "user1",


      "email": "user1@example.com",


      "phone_number" : "789-975-0000"


  }


}



Once you receive this as incoming json request parse this and get the value of ritm json key i.e. RITM0001


get the variables value from the json by parsing it and update the variable with the values.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Eli,



Fields are at dictionary level so you can directly update those.


Catalog item variables values are stored in the following table i.e. Variable Ownership sc_item_option_mtom



One more thing you can do is send the RITM number and values for the variables and use PUT method and get the json request and update the corresponding variables by querying the RITM number



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Thank you Ankur!



Can you please elaborate a bit more on the second option? maybe an example?


Hi Eli,



Create a Scripted REST API and resource as PUT.


Have some sample json incoming request such as below:


{


  "ritm": "RITM0001",


  "variables": {


      "user": "user1",


      "email": "user1@example.com",


      "phone_number" : "789-975-0000"


  }


}



Once you receive this as incoming json request parse this and get the value of ritm json key i.e. RITM0001


get the variables value from the json by parsing it and update the variable with the values.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi Ankur,

I had a similar requirement.

 

My issue was , using PUTalthough i could retrieve the value of  a (no role read acl) reference field.

But was not able to update it, neither was able to update a string fields.

 

sysparm_input_display_value and sysparm_display_value is set true

JSON query format:

{"variables.template":"1-Generic Template","comments":"test1"}

 

Response(number and variables.template to be returned):

 

{
  "result": {
    "number": "RITM0691191",
    "variables.template": "Account Access"
  }
}