How to pass a string input in a flow designer to a reference field

Atheher Fathima
Mega Guru

Hi Team,

 

I have a requirement where i have a subflow that will be used in a scripted restAPI. in the subflow we have defined a input "Assigned_to" as string. expectation is that if the user passes the assigned to value via API, it should updated the corresponding assigned to field in an incident. As assigned to in incident form is a reference field and the input is string, the value passed by API is not updating in the incident. how can i achieve this?

 

any help on this is greatly appreciated

4 REPLIES 4

manjusha_
Kilo Sage

@Atheher Fathima 

 

Are you receiving assigned to value from api as a string?

 

Thanks,

Manjusha Bangale

 

Yes @manjusha_ 

Riya Verma
Kilo Sage
Kilo Sage

Hi @Atheher Fathima ,

 

Hope you are doing great.

To achieve this, you can use a combination of Flow Designer and a Scripted REST API. Here are the steps you can follow:

  1. Create a Flow in Flow Designer:

    • Add an input variable named "Assigned_to" of type string.
    • Add an action to retrieve the incident record based on your criteria.
  2. Add a Scripted Action:

    • After retrieving the incident, add a Scripted Action.
    • Use JavaScript to convert the string input into a reference field value. You'll need to query the User table to get the sys_id of the user based on the provided string.
      // Assuming 'assignedToString' is the string input from the API
      var userGR = new GlideRecord('sys_user');
      userGR.addQuery('name', assignedToString);
      userGR.query();
      
      if (userGR.next()) {
          var assignedToSysId = userGR.sys_id;
          current.incident_field = assignedToSysId; // Set the incident field to the sys_id
      }
      ​
  3. Use a Flow Designer action to update the incident record. Set the "Assigned to" field to the sys_id obtained from the User table.

  4. Expose the Flow via Scripted REST API:

    • Create a Scripted REST API that triggers the Flow you've just created.
    • Make sure to map the input from the API request to the "Assigned_to" variable in your Flow.
 
 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hi Riya, 

 

I did give it a try, i have a input variable defined as "Assigned To" . In Create incident i tried to add the scripted action,but getting an error that assigned to is not defined. 

AtheherFathima_0-1696001230561.png

I tried using the script in step 3 Create incident record

AtheherFathima_1-1696001284300.png

 

Please advise