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

Ankur Bawiskar
Tera Patron
Tera Patron

@1_DipikaD 

error 422 means server can't process the request.

you are giving error if source is phone so if you are giving source as phone in your API request then it will error out

it's working as expected then what's the concern?

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

Thanks for your response Ankur. Actually I don't want want the 422 error. What changes should I make on that code so that i can get 200 success response ?

@1_DipikaD 

http 200 means you should allow the update

so you need to remove the line which sets out error

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

yes, correct . I want to remove the line and allow update.

 

@Ankur Bawiskar  could you please reply on it soon if possible ? It is quite urgent.