Make active filed as true in target table while importing data through data source(excel)

Devi D
Tera Expert

Hi Everyone ,

When we are importing data into user table through data source .

Currently when "Active" field is not filled in the excel sheet for a record , the value in the active field is populated a "False" for that record. During new record creation , ensure that default value of active field is taken as "True".

For this i have written code in 2 way as below and both are on before transform and not working.

option1 : not working

{

if (action=='insert'){

target.active =true;

}

 

option2 : not working

 

{

if (action=='insert'){

var gr=new GlideRecord('sys_user');

gr.addQuery('user_name',source.u_user_id);

gr.query();

if(gr.next()){

gr.active =true;

gr.update();

}

Kindly help me on this .

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Devi D 

please share your complete field mapping screenshot, transform map screenshot and transform script screenshot

this should work in onBefore transform script

{
if (action=='insert'){
target.active =true;
}

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

View solution in original post

9 REPLIES 9

Najmuddin Mohd
Mega Sage

Hello @Devi D ,

The alternative would be to make the field by Default Active to true and once the upload is completed make default as false.

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

As per requirement by default it should be "False"

Can you try by gr.setValue('active','true');
Using the Single quotes.

Or just right a business rule, when ever a user is created, make Active = true.

Community Alums
Not applicable

Hi @Devi D 

Can you try with below script in Before transform Script -

if (action == 'insert') {
  if (!source.active) {
    target.active = true;
  }
}