Need help for one of Transform script

Are Kaveri
Tera Contributor

Hi Everyone,

 

I am facing below issue for one of the transform map.

we have active and inactive users in User table.

The Username is mapping to inactive id of user record instead of active user.

 

We have a Datasource of Excel we need load data to our Target Table.

Source table : Users details table(imp_user_details)

Target Table : Users table(sys_user)

 

Field maps:

source fieldtarget fieldcoalesce
using scriptactivetrue
u_user_namestu_user_namefalse
u_emailemailtrue
u_user_idstu_user_idfalse

 

 

In my source field script :

answer = (function transformEntry(source) {

	return true; 

})(source);

 

now i am facing issue as the user name was tagging to inactive user instead of active users.

 

I am not understanding what is the issue.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Are Kaveri 

as per your field map you have marked 2 fields as coalesce

If either value is not found, it will go ahead and create

Do you want to create users or update users?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

1. I need to update user with User name . I dont want to create any. 

2. it need to update Stu User name only for active users

 

The below is before tranform script where i was restricting insert action

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    if (action == 'insert') {
        log.error("User do not exist");
        ignore = true;
    }

})(source, map, log, target);

@Are Kaveri 

then handle this using onBefore transform script only and remove all field maps but keep field map only for email with coalesce=true

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    if (action == 'insert') {
        log.error("User do not exist");
        ignore = true;
    }
	
	if(target.active  == true && action == 'update'){
		target.stu_user_id = source.u_user_id;
		target.stu_user_name = source.u_user_name;
	}

})(source, map, log, target);

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

NitishKumar0012
Tera Guru

reurn 'true'