How to automatically autofill a reference field in an action function in Now Mobile?

Roman Mathieu
Tera Contributor

Hello everyone. I'll try to be as clear as possible but it's quite difficult to explain.

I have an applet 'Activity': find_real_file.png

I have an action item and an action function :

find_real_file.png

find_real_file.png

And in my action function, participant number (one of my UI parameters) looks actually like this : 

find_real_file.png

But, on the app, it generates a list of all the participant numbers who have records.

What I want is to autofill the participant number for the logged-in user or to have a list with only 1 participant number (the one of the logged-in user) when the participant creates a new steps record. 

I also tried the autofill function with user, source field and append encoded query as input types but I always get the same message : 'Could not execute the action'. 

 

Here are some more screenshots of the app itself and the applet in question. Hope you'll be able to help me 🙂

find_real_file.pngfind_real_file.pngfind_real_file.png

Thank you, 

Roman

1 ACCEPTED SOLUTION

S_bastien Van 1
Tera Expert

Hi Roman,

 

Since you said the following;

What I want is to autofill the participant number for the logged-in user or to have a list with only 1 participant number (the one of the logged-in user) when the participant creates a new steps record.

I am assuming it would not be a bad thing if that option is not shown to the users but insteads just gets auto-populated with the participant number of the logged in user?

 

If that is the case, I would just suggest leaving out UI parameter for that participant number.

On the action item itself then, I would use a 'Script' type instead of a 'New' type and just script the creation of the record. Also make sure that the name of the item parameters for that action item do not include a space (Steps Records date -> steps_records_date)

The script would then look something like this:

(function WriteBackAction(input) {
  // Initialize a new record
  var stepsRecordsGR = new GlideRecord('x_aspas_steps_chal_steps_records');
  stepsRecordsGR.initialize();

  // write some code to retrieve the participant number of the logged in user
  // The logged in user sys_id can be found with gs.getUserID()
  // Save the number to a variable
  var participantNumber = ....
  stepsRecordsGR.setValue('participant_number', participantNumber);

  // Set the other values by using the input object (which contains the action item 
params)
  stepsRecordsGR.setValue('description', input.steps_records_description);
  ...

  // Insert the new record
  stepsRecordsGR.insert();
})(input);

Kind regards,

Sébastien Van Someren

View solution in original post

3 REPLIES 3

S_bastien Van 1
Tera Expert

Hi Roman,

 

Since you said the following;

What I want is to autofill the participant number for the logged-in user or to have a list with only 1 participant number (the one of the logged-in user) when the participant creates a new steps record.

I am assuming it would not be a bad thing if that option is not shown to the users but insteads just gets auto-populated with the participant number of the logged in user?

 

If that is the case, I would just suggest leaving out UI parameter for that participant number.

On the action item itself then, I would use a 'Script' type instead of a 'New' type and just script the creation of the record. Also make sure that the name of the item parameters for that action item do not include a space (Steps Records date -> steps_records_date)

The script would then look something like this:

(function WriteBackAction(input) {
  // Initialize a new record
  var stepsRecordsGR = new GlideRecord('x_aspas_steps_chal_steps_records');
  stepsRecordsGR.initialize();

  // write some code to retrieve the participant number of the logged in user
  // The logged in user sys_id can be found with gs.getUserID()
  // Save the number to a variable
  var participantNumber = ....
  stepsRecordsGR.setValue('participant_number', participantNumber);

  // Set the other values by using the input object (which contains the action item 
params)
  stepsRecordsGR.setValue('description', input.steps_records_description);
  ...

  // Insert the new record
  stepsRecordsGR.insert();
})(input);

Kind regards,

Sébastien Van Someren

Thanks a lot. I started from your code, modified it a bit and it worked ! 🙂

Hello Mathieu,


can you share your code please? I have the same problem as you, I tried the code shared by Sebastien, but it does not work for me !!

 

Best regards