Update variables using PUT/PATCH method in RITM from third party

Bijender
Tera Guru

Hi,

We got the record created vis POST method , but now need to update the variable of existing RITM.

Tried some method shared in community and created a Scripted REST API, but seems I am doing something wrong as it is not working. 

Please advise.

Script REST API created:

 

Bijender_2-1696240695984.png

 

Error:

Bijender_0-1696241261310.png

 

Bijender_2-1696241361964.png

 

 

Regards,
B

 

 

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@Bijender You are mentioning RITM number in relative path and in the script you are trying to fetch it from query parameter which is wrong. You need to fetch it from path parameter. Follow below steps

 

1) Put the below script in script section

 

 

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

var ritmNumber = request.pathParams.number;
var reqBody = request.body.data;

if (ritmNumber) {
var bodyObject = JSON.stringify(reqBody);
var parser = JSON.parse(bodyObject);
var variables = parser.variables;         // get the variables data

var variablesObject = JSON.stringify(variables);  
var variableElements = JSON.parse(variablesObject); //parse variables data

var ritmObj = new GlideRecord('sc_req_item');
if (ritmObj.get('number', ritmNumber))
{
gs.info(ritmObj.ritmNumber);
ritmObj.variables.new_email = variableElements.new_email;
var recordUpdated = ritmObj.update();
}

if (recordUpdated)
{
var body = {};
body.status = 'record successfully updated';
response.setBody(body);             // set the response body

}
}
})(request, response);

 

 

 

2) As you are already passing the number in path parameter the no need pass again in the request body. Sample request body as below

{
variables: {
"new_email": "servicenow12345@gmail.com"
}
}

SANDEEP28_0-1696245812960.png

 

SANDEEP28_1-1696245836056.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

View solution in original post

11 REPLIES 11

Peter Bodelier
Giga Sage

Hi @Bijender,

 

How does it respond when you put the RITM number directly in the endpoint, instead of in the header?

 

Replace the single quotes, by double quotes in the body.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter,

Tried , but no success same error.

 

Bijender_1-1696241628110.png

 

 

Regards,
Bijender

Hi @Bijender 

 

Variables is still surrounded by single quotes, and I still see {number} instead of RITMxxxx in the endpoint url.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter,

Same error, tried commenting number in body also, but same error

Bijender_0-1696242514570.png

 


Regards,
Bijender