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 

did you requirement change and you don't want this validation?

if( source != 'SPAM Submission' && source != 'Application monitoring' &&ci.indexOf('Elastic')<0&&scope =='Yes'){
if((gr.subcategory != 'Domain Impersonation' ) && (gr.category != 'Malicious Code' && gr.subcategory != 'Malicious Attachment') && (gr.category != 'Unauthorized Access')) {

If yes then remove hose IF lines and simply allow the update to happen

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 

I think there is contradiction between 2 if conditions but  I want both conditions to meet . Could you please help me to  fix it ?

 

Thank You

@1_DipikaD 

please discuss with your customer what's the exact requirement and then fix by adding/removing the IF conditions.

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