Skip to main content

Hi,

 

what function can be called to get row from response of createInsertRequest?

 

I have script to insert person_cal_except table.  The aim is to get row and exception_id of the new created record..

 

My script is like this:

var newRec = {};
        newRec.person_id = personId;
        newRec.exception_type = exceptionType;
        newRec.start_dttm = startDttm;
        newRec.end_dttm = endDttm;
        newRec.user_def1 = approved;
        newRec.available = available;
        var personCalExceptReq = createInsertRequest('person_cal_except', newRec);
        var response = executeRequest(personCalExceptReq);
    
        if (response='$type'] == 'ErrorResponse')      
          {
            displayUserToast(getMessage('cUnabletoAddCalException','Information') + personId + '  ' + response.message,'error'); 
          }
          else
          {
              // alert('response' + size(response));
                exceptionId = ?????? ;
                // alert('exception Id: ' + exceptionId);
                  
                               
                displayUserToast(getMessage('cCalExceptionCreated','Information') + exceptionId, 'INFO'); 
               }

 

Thanks in advance for your response,

~Juni

Hey @JuniSihombing 

I haven’t tried it myself, but try one of the following

  • response.metrix_run_log_id
  • response.error

Cheers!


Hi @Shneor Cheshin,

thank you for your feedback.

I tried using  response.metrix_run_lod_id and response.error . Unfortunately both are undefined parameters.

~Juni


Hi @JuniSihombing ,

I have tested your client script with some sample data and was able to access the result in the way mentioned below. 

var startDttm = new Date();
var endDttm=startDttm+days(1);
var available = "N";
var personId = getControlValue('person', 'person_id');
var last_name = getControlValue('person', 'last_name');

if (last_name != null && last_name=='TEST')
{
var newRec = {};
newRec.person_id = personId;
newRec.exception_type = "SICK";
newRec.start_dttm = startDttm;
newRec.end_dttm = endDttm;
newRec.available = available;
var personCalExceptReq = createInsertRequest('person_cal_except', newRec);
var response = executeRequest(personCalExceptReq);

if (responsen'$type'] == 'ErrorResponse')
{
displayUserToast(getMessage('cUnabletoAddCalException','Information') + personId + ' ' + response.message,'error');
}
else if (response != null)
{
calExceptArray = normalizeToArray(response);
//if we have only one result from the insertion, simply add this
var myRow = calExceptArrayr0];
alert('The Cal Except Id is: ' + myRow.itemt'exception_id']);
//if we have multiple results from the insertion, then traverse through
for(var i=0; i < size(calExceptArray); ++i)
{
var theRow = calExceptArrayri];
alert('The cal except id generated from the loop is: ' + theRow.itemt'exception_id']);
}

}

}

As mentioned, if your response returns only one result, then you do not need to traverse through the elements. You can simply alter your script as below

calExceptArray = normalizeToArray(response);
var myRow = calExceptArrayr0];
alert('The cal except id is ' + myRow.itemt'exception_id']);

Hope this helps.


Thank you @Saranga Amaraweera .

The solution you gave works!

 

cheers,

~Juni


Reply