Insert data in one time

SupriyaWaghmode
Kilo Sage

I have created the scheduled job to insert data into transform map , 

rest mestods are different but , I wants insert data at one time

 var r = new sn_ws.RESTMessageV2('LR-Successfactor-Outbound-Integration', 'PerPerson'); // Call PerPerson Job
    var response = r.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();
    gs.log("SW:Person" + responseBody);

    if (httpStatus == 200) {
        var jsonObj = gs.xmlToJSON(responseBody);
        var str = JSON.stringify(jsonObj);
        var jsonbody = JSON.parse(str);
        gs.log("SW:Person" + jsonbody);

        var per_PersonJob = new GlideRecord("u_lr_successfactors_data");
        for (i = 0; i < jsonbody.feed.entry.length; i++) {
            per_PersonJob.initialize();
            per_PersonJob.u_employee_number = jsonbody.feed.entry[i].content['m:properties']['d:personIdExternal'];
            per_PersonJob.insert();
        }
    }
    var rcom = new sn_ws.RESTMessageV2('LR-Successfactor-Outbound-Integration', 'EmpJob'); //Call Emp Job
    var responsecom = rcom.execute();
    var responseBodycom = responsecom.getBody();
    var httpStatuscom = responsecom.getStatusCode();
    gs.log("SW-Empjob++"+responseBodycom);

    if (httpStatuscom == 200) {
        var jsonObjcom = gs.xmlToJSON(responseBodycom);
        var strcom = JSON.stringify(jsonObjcom);
        var jsonbodycom = JSON.parse(strcom);

        var empJob = new GlideRecord("u_lr_successfactors_data");
        for (j = 0; j < jsonbodycom.feed.entry.length; j++) {

            empJob.initialize();
   
            empJob.u_employee_number = jsonbodycom.feed.entry[j].content['m:properties']['d:personIdExternal'];
            empJob.u_assignment_status = jsonbodycom.feed.entry[j].content['m:properties']['d:employmentType'];
            empJob.u_business_area = jsonbodycom.feed.entry[j].content['m:properties']['d:customString20'];
            empJob.u_function = jsonbodycom.feed.entry[j].content['m:properties']['d:customString15'];

            empJob.u_position = jsonbodycom.feed.entry[j].content['m:properties']['d:jobTitle'];
            empJob.u_employment_type = jsonbodycom.feed.entry[j].content['m:properties']['d:employeeType'];
            //empJob.u_probation_end_date = jsonbodycom.feed.entry[j].content['m:properties']['d:probationPeriodEndDate'];

            var probationDate = jsonbodycom.feed.entry[j].content['m:properties']['d:probationPeriodEndDate'];
            empJob.u_probation_end_date = probationDate ? probationDate.toISOString() : null;
            empJob.insert();
        }
    }
1 ACCEPTED SOLUTION
4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, unfortunately your post and code do not make your requirement\intention clear.

Are you trying to insert all of your records via 1 row\payload?

Are you trying to use 1 payload to inserts (or update) related records in multiple tables?

Perhaps you could update this thread with clear details of your requirement?

Information about the outcome\target records and example of payload(s) might also help the community with a better understanding of your requirement.

 

 

Yes , I wants to insert on row with all multiple value . 

I change the code :

 

try {
    var r = new sn_ws.RESTMessageV2('LR-Successfactor-Outbound-Integration', 'PerPerson'); // Call PerPerson Job
    var response = r.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();

    var rcom = new sn_ws.RESTMessageV2('LR-Successfactor-Outbound-Integration', 'EmpJob'); //Call Emp Job
    var responsecom = rcom.execute();
    var responseBodycom = responsecom.getBody();
    var httpStatuscom = responsecom.getStatusCode();

    var rLoc = new sn_ws.RESTMessageV2('LR-Successfactor-Outbound-Integration', 'EmpEmployment'); //Call EmpEmployment
    var responseLoc = rLoc.execute();
    var responseBodyLoc = responseLoc.getBody();
    var httpStatusLoc = responseLoc.getStatusCode();


    gs.log("SW:Person" + responseBody);

    if (httpStatus == 200 && (httpStatuscom == 200 || httpStatusLoc == 200)) {
        var jsonObj = gs.xmlToJSON(responseBody);
        var str = JSON.stringify(jsonObj);
        var jsonbody = JSON.parse(str);

        var jsonObjcom = gs.xmlToJSON(responseBodycom);
        var strcom = JSON.stringify(jsonObjcom);
        var jsonbodycom = JSON.parse(strcom);

        var jsonObjLoc = gs.xmlToJSON(responseBodyLoc);
        var strLoc = JSON.stringify(jsonObjLoc);
        var jsonbodyLoc = JSON.parse(strLoc);


        var per_PersonJob = new GlideRecord("u_lr_successfactors_data");
        per_PersonJob.initialize();
        for (i = 0; i < jsonbody.feed.entry.length; i++) {

            per_PersonJob.u_employee_number = jsonbody.feed.entry[i].content['m:properties']['d:personIdExternal'];

        }
        for (j = 0; j < jsonbodycom.feed.entry.length; j++) {



            //per_PersonJob.u_employee_number = jsonbodycom.feed.entry[j].content['m:properties']['d:d:userId'];
            per_PersonJob.u_assignment_status = jsonbodycom.feed.entry[j].content['m:properties']['d:employmentType'];
            per_PersonJob.u_business_area = jsonbodycom.feed.entry[j].content['m:properties']['d:customString20'];
            per_PersonJob.u_function = jsonbodycom.feed.entry[j].content['m:properties']['d:customString15'];

            per_PersonJob.u_position = jsonbodycom.feed.entry[j].content['m:properties']['d:jobTitle'];
            per_PersonJob.u_employment_type = jsonbodycom.feed.entry[j].content['m:properties']['d:employeeType'];
            //per_PersonJob.u_probation_end_date = jsonbodycom.feed.entry[j].content['m:properties']['d:probationPeriodEndDate'];

            var probationDate = jsonbodycom.feed.entry[j].content['m:properties']['d:probationPeriodEndDate'];
            per_PersonJob.u_probation_end_date = probationDate ? probationDate.toISOString() : null;

        }

        for (m = 0; m < jsonbodyLoc.feed.entry.length; m++) {



            var seniorityDate = jsonbodyLoc.feed.entry[m].content['m:properties']['d:seniorityDate'];
            per_PersonJob.u_employment_start_date = seniorityDate ? seniorityDate.toISOString() : null;

            var endDate = jsonbodyLoc.feed.entry[m].content['m:properties']['d:endDate'];
            per_PersonJob.u_employment_end_date = endDate ? endDate.toISOString() : null;


        }
        per_PersonJob.insert();
    }  


} catch (ex) {
    var message = ex.message;
    gs.log("LR-SuccessfactorJob: message failure" + message);
}
 
Challenge is getting object for function , position ,business area .

Hi, supplying your code (as text) is a great start, but with no details of your payload/JSON message the community has no way to evaluate your content.

Your code seems to imply a multi-dimensional array within the array 'feed.entry' ?
If this is correct then you would need to be referencing the elements of the multidimensional array by their index\element ID and not by 'name', you also have these element ID's as 'strings'.
I would suspect that you are looking for object name: value pairs ?
but with no details that's just a guess, perhaps you could update this thread with sample payload?

Resolve the issue.