Set subcategory based on category in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 03:16 PM
Hello,
I want to see if there is a way to set a subcategory based on a category in the script of a record producer. I am newbie when it comes to scripting so any help is greatly appreciated!
I want something like:
if current.category = "Software & Web Applications" then current.subcategory = "Code42";
Thanks,
Grace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 10:32 PM
Hi,
You can use the below code in your Record Producer form to have the functionality implemented:
var cat = producer.u_category; //Replace your Category Variable Name here
if(cat == 'value1')
{
current.u_subcategory = 'Give your value here which you want to set';
}
else if(cat == 'value2')
{
current.u_subcategory = 'Give your value here which you want to set';
}
If Subcategory is a choice field give the backend value of the choice in the place where you are setting the value of subcategory field. If Subcategory is a reference field then you need to give the Sys_Id of the referenced value. Better would be for reference field store the Sysid in Property and call the same as mentioned below:
if(cat == 'value1')
{
current.u_subcategory = gs.getproperty('Give your property Name');
}
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 10:53 AM
Thank you Shloke. I tried both codes you included but neither seemed to work. Can you take a look below and see if I'm missing something? Also, I should add that in my variables I have subcategory and subcategory2 and ui policies in place to show either one depending on the category selected. I have a feelingg that by having subcategory2, it is not showing the value.
**The subcategory for software should be Code42 (which I added the sys_id for)**
1st Attempt
current.assigned_to = ('cd4a0ba013076200720e7a42f244b0a1');
current.assignment_group.setDisplayValue("ITS Project Management");
current.contact_type = "email";
var cat = producer.u_software; //Replace your Category variable name here
if(cat == 'Software & Web Applications')
{
current.u_subcategory ='001a637f4fc6c380010601b28110c7f6';
}
2nd Attempt
current.assigned_to = ('cd4a0ba013076200720e7a42f244b0a1');
current.assignment_group.setDisplayValue("ITS Project Management");
current.contact_type = "email";
if(cat == 'c9b52deb4f4a4380c360b3318110c794')
{
current.u_subcategory = gs.getProperty('001a637f4fc6c380010601b28110c7f6');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2017 06:41 PM
Your code looks correct.Few things to check from your end.
1) Check your Category Variable Name correctly as you have defined in your Record Producer. From the screenshot you have attached I can see a Variable Category(backend name as "category") while in the code which you shared above you are checking for a variable which is "u_software" (var cat = producer.u_software;).
2) Once this has been done check the correct backend value for this variable on basis of which you want to populate subcategory.
if(cat == 'Software & Web Applications')
{
....
}
3) Last check would be the value whether it is present or not for your reference Subcategory field in the form(not on Record Producer). If it is copy the correct sys id and paste it in your code.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 11:51 PM
Thanks for the update Grace. Do you have category field on the record producer form. If yes then you can have script as part of record producer. Please confirm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2017 10:54 AM