Could not update record through Rest API explorer .

1_DipikaD
Kilo Sage

Hi All,

I am getting 422 service error while using PUT method on Rest API explorer  for incident table.

I have the below  script in Scripted REST Resource table for the API definition. What should I make changes to get 200 success response to update the record.

 

 

if( source == 'phone'){
        if( (gr.category == 'hardware' || gr.category == 'software') && (gr.subcategory == 'Imposter' || gr.subcategory == ' Attachment')) {
        msg = 'Able to update Incident. Error: This SIR is restricted to be updated via API.';
        errDet = 'Can update the  incident which source is phone: ' + number;
        serviceError = RESTUtils.buildErrorObject(422, msg, errDet);
        response.setError(serviceError);
        msg = 'Record updated successfully';
        response.setBody(responseBody);
        return;
        }
    }
 
Please let me know if you need more information.
 
Thank You
17 REPLIES 17

@1_DipikaD 

please share complete script and not partial, I will be able to respond tomorrow morning IST.

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

Thank you very much  for your insights.

@1_DipikaD 

your script already has logic for success, just pick from there and place in your code

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

@Ankur Bawiskar  Could you please mention which one is for success response. But there are no 200 success response have been passed as per my knowledge. 

 

Thank you

@1_DipikaD 

the start and end code already has successfully updated message

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