Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

400 (BadRequest) - Custom Object

rafael
Contributor

Hi

We are creating a custom object to fill a field in the main from the sub-form. However, it is not working and we are receiving the message 400 (BadRequest).

Sub-form:

 

<script type="text/javascript">
  function updateParentRecord() { 
// Get the parent record tracking number 
var trackingId = sessionStorage.getItem('trackingId');
// The parent record field Log Changed will be referenced by its field Id 21913 
var fieldId = 21913; 
// Generate a unique value to ensure that the notification always evaluates true on changed 
var timestamp = new Date().valueOf(); 
// Construct the body of the web request in JSON format, Id, Level Id, and Field Id are mandatory for a successful request 
// The timestamp value is included to update the Log Changed field 
var body = '{"Content":{"Id":' + trackingId + ',"LevelId": 83,"FieldContents":{"' + fieldId + '":{"Type": 1, "Value":"' + timestamp + '", "FieldId":' + fieldId + '}}}}' 
// Construct and send the web request 
var request = new XMLHttpRequest(); 
       console.log("body:", body);
       request.open("PUT", "https://url/platformapi/core/content/"); 
request.setRequestHeader("Accept", "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 
        request.setRequestHeader('x-csrf-token',(window.sessionStorage)?window.sessionStorage.getItem("x-csrf-token"):parent.parent.ArcherApp.globals['xCsrfToken']);
request.setRequestHeader("Content-Type", "application/json"); 
request.send(body);
}
</script>

 

Main-form:

 

<script>
var trackingId = 0
sessionStorage.setItem('trackingId',getRecordId());
console.log("tracking:", trackingId);
</script>

 

Payload:

 

{
  "Id": 13905952,
  "LevelId": 83,
  "FieldContents": {
    "21913": {
      "Type": 1,
      "Value": "1690318250499",
      "FieldId": 21913
    }
  }
}

 

Error:

Status Code: 400 (BadRequest) - Please view the error log for details.
 
We are using Archer SaaS Version 6.13
 
Could anyone please help us?
 
Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions

Have you tried @Kevin_Corbett suggestion, Solved: Re: Sub-Forms and Last Updated - Page 2 - Archer Community - 423759 (archerirm.community) from the same link you gave?

Is the level Id correct; it's not the application/module id.

 Advisory Consultant

View solution in original post

6 REPLIES 6

Anonymous
Not applicable

@rafael,

I believe your request is missing "SubformFieldId" : ### metadata at the end.

Like check from here: https://www.archerirm.community/t5/archer-api-users/archer-api-create-sub-forms-error-powershell/m-p/622635#M960

DavidPetty
Archer Employee
Archer Employee

It might be the time value you're setting.  For your timestamp variable use this instead, new Date().toLocaleDateString();

Is the parent record in edit mode when the user creates the sub-form record?  If so, there might be an issue with the API making the change to the parent record on the backend but not being updated in the browser when the user leaves the sub-form record which would cause the record confict warning to appear when the user saves the parent record.

Best to use session storgate instead on the sub-form and have the parent look for it when the page refreshes coming back from the sub-from record.

 Advisory Consultant

Hi

Thanks for the reply. In our case, we are updating the parent form. I understand this case is when we would like to update the sub-form

Thanks again.

Hi David,

We updated the timestamp, but we still received the same error:

{
  "Id": 13905952,
  "LevelId": 83,
  "FieldContents": {
    "21913": {
      "Type": 1,
      "Value": "7/26/2023",
      "FieldId": 21913
    }
  }
}

We were using this code as a sample: https://www.archerirm.community/t5/archer-custom-objects-forum/sub-forms-and-last-updated/td-p/423759/page/2

Would you have any sample code on how to achieve this another way? We need to create a notification when the sub-form is updated. 

Thanks for the help.

Have you tried @Kevin_Corbett suggestion, Solved: Re: Sub-Forms and Last Updated - Page 2 - Archer Community - 423759 (archerirm.community) from the same link you gave?

Is the level Id correct; it's not the application/module id.

 Advisory Consultant

We tried the other suggestion, and it worked as we needed. Thank you for your help