You are viewing limited content. For full access, please sign in.

Question

Question

JavaScript Filter character limit - User task assigned to a team-

asked on February 29, 2020

Hello community,

I managed to assign a task to a particular user in a team via the Javascript filter:

I have 40 locations (variable drop-down list), and 4 people who must approve the tasks depend on the location (each approval has 10 locations associated with it).

I followed this solution:
switch ($ util.getValue ( 'location_field')) {
     box 'LOC1':
         $ result = team.findMembersByRole ('Approve1');
     break;
}
But given the number of locations and assumptions I have (with a limit of 1000 characters) it is impossible for me to finish. is there a trick to bypassing this character limit? I thought of creating several filters but we can only use one filter at a time ...

Your ideas and proposals are welcome,

Thank you !
 

0 0

Replies

replied on March 2, 2020 Show version history

Hi Amina,

You could give this a try to hopefully fit in all of the locations:

var locations = ["LOC1","LOC2","LOC3"];
var roles = ["Approve1","Approve2","Approve3"];
var val = $util.getValue("location_field");
for (var i in locations) {
  if (val == locations[i])
    $result = team.findMembersByRole(roles[i]);
}

LOC1 corresponds to Approve1, LOC2 to Approve2, etc. You will only need to add the locations and roles to the arrays in the first two lines and the rest of the code will only need to be there once. My example uses three.

I have not tested it on a Forms filter but the JavaScript should work. Depending on the length of characters in each location name and role name/filter, you may be able to fit in all 40.

If it's still not short enough, I'd recommend using shorter variable names in the dropdown field, so the locations array is shorter. For example, if this is my dropdown, then I'd replace LOC1 in the code with L1, LOC2 with L2, etc.:

 

You could also shrink the code by an additional almost 40 characters like this:

var locations=["LOC1","LOC2","LOC3"],
roles=["Approve1","Approve2","Approve3"],
val=$util.getValue("location_field");for(var i in locations){if(val==locations[i])$result=team.findMembersByRole(roles[i]);}

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.