The CreatorCon Call for Content is officially open! Get started here.

Append Employee Hire Date

preethigovi
Tera Contributor

Hi Team,

I need to append employee Hire date to Journey table title field. I need to do this for 1500 plus users.

That is like: Digital Onboarding - NETHERLANDS CornMine AMP Last name - 2024-02-14

 

I wrote fix script to pass the employee ids from journey table

 

var jnyMem = [];
var mapped_id = [];
var associatedDate;
var journeyGR = new GlideRecord('sn_jny_journey');
journeyGR.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');
journeyGR.query();
while (journeyGR.next()) {
    jnyMem.push(journeyGR.getValue('employee'));
}
gs.info('Preethijny1 ' + JSON.stringify(jnyMem))

var hr_include = new sn_hr_core.getHiredate().getHrDate(jnyMem);
gs.info('Preethijny4 ' + JSON.stringify(hr_include));
var empMmber = new GlideRecord('sn_jny_journey');
empMmber.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');
//empMmber.addQuery('employee', 'IN', Object.keys(hr_include).join(','));
empMmber.query();
while (empMmber.next()) {
    var emp_id = empMmber.getValue('employee');
    for(var i=0;i<jnyMem.length;i++){
    //associatedHireDate = hr_include[emp_id];
    var a= jnyMem[i]=hr_include[i];
    empMmber.title += ' ' + '-' + a;
    gs.info('preethi7 ' + empMmber.title);
}
gs.info('preethi7 ' + empMmber.title);
gs.info('preethi8 ' + emp_id);
 
preethigovi_0-1730801643166.png

Please help to correct

 

 

 

1 ACCEPTED SOLUTION

Abhay Kumar1
Giga Sage

@preethigovi please find the updated one and it should update each journey record with hire date:

var journeyGR = new GlideRecord('sn_jny_journey');

journeyGR.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');

journeyGR.query();

 

var jnyMem = []; // Store employee IDs for which we need hire dates

while (journeyGR.next()) {

    jnyMem.push(journeyGR.getValue('employee'));

}

 

// Retrieve hire dates for all employees in one call (assuming getHrDate can handle arrays)

var hr_include = new sn_hr_core.getHiredate().getHrDate(jnyMem);

gs.info('Hire dates retrieved: ' + JSON.stringify(hr_include));

 

// Update each Journey record

var empMmber = new GlideRecord('sn_jny_journey');

empMmber.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');

empMmber.query();

 

while (empMmber.next()) {

    var emp_id = empMmber.getValue('employee');

    var hireDate = hr_include[emp_id]; // Get the hire date for the employee

 

    if (hireDate) {

        // Build the new title

        var newTitle = empMmber.title + ' - ' + hireDate;

        empMmber.title = newTitle;

 

        // Update the record

        empMmber.update();

        gs.info('Updated title for ' + emp_id + ': ' + newTitle);

    } else {

        gs.info('Hire date not found for employee ID ' + emp_id);

    }

}

Hope this helps you.

 

View solution in original post

5 REPLIES 5

palanikumar
Giga Sage
Giga Sage

Hi,

From this output, it is clear that some of the object is not converted into string.

Make change to this line where empMmber.title is set:

empMmber.title += ' ' + '-' + JSON.stringify(a);

 

Also ensure that below line is correct:

var a= jnyMem[i]=hr_include[i];

Thank you,
Palani

Hi @palanikumar .

Even then issue happens. I want to map the hire date that i got from script include to respective employees

preethigovi_0-1730804321619.png

this is what i got from script include

Can you update the below line and let me know the output

 var a= jnyMem[i] + " - " + hr_include[i];

Thank you,
Palani

Abhay Kumar1
Giga Sage

@preethigovi please find the updated one and it should update each journey record with hire date:

var journeyGR = new GlideRecord('sn_jny_journey');

journeyGR.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');

journeyGR.query();

 

var jnyMem = []; // Store employee IDs for which we need hire dates

while (journeyGR.next()) {

    jnyMem.push(journeyGR.getValue('employee'));

}

 

// Retrieve hire dates for all employees in one call (assuming getHrDate can handle arrays)

var hr_include = new sn_hr_core.getHiredate().getHrDate(jnyMem);

gs.info('Hire dates retrieved: ' + JSON.stringify(hr_include));

 

// Update each Journey record

var empMmber = new GlideRecord('sn_jny_journey');

empMmber.addEncodedQuery('numberINJNY00000949,JNY00000369,JNY00000365');

empMmber.query();

 

while (empMmber.next()) {

    var emp_id = empMmber.getValue('employee');

    var hireDate = hr_include[emp_id]; // Get the hire date for the employee

 

    if (hireDate) {

        // Build the new title

        var newTitle = empMmber.title + ' - ' + hireDate;

        empMmber.title = newTitle;

 

        // Update the record

        empMmber.update();

        gs.info('Updated title for ' + emp_id + ': ' + newTitle);

    } else {

        gs.info('Hire date not found for employee ID ' + emp_id);

    }

}

Hope this helps you.