How to validate if list collector has no value in record producer script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 03:08 PM
Please can someone help as I have tried what I think is everything and can't get this to work. I'm worried I might be going around in circles and stuck focusing on one thing and maybe missing something really straight forward.
What is the correct syntax to validate if a list collector has no value in a record producer script?
currently this is my code:
var clients = "";
clients = producer.u_primary_client.getDisplayValue();
var additionalClients = producer.u_portfolio_list.toString();
if (additionalClients !="")
{
clients += ", " + producer.u_portfolios_list.getDisplayValue();
}
current.u_clients = clients;
On my form when nothing is selected in u_portfolio_list (list collector) and the field is left completely blank it still enters the IF statement and prints the primary client followed by a comma.
I have tried all of the following:
if (additionalClients !== "")
if (additionalClients !== NULL) and if (additionalClients != NULL)
if (producer.u_portfolio_list.getDisplayValue() !== "") and if (producer.u_portfolio_list.getDisplayValue() != "")
if (producer.u_portfolio_list. !== NULL) and if (producer.u_portfolio_list. != NULL)
When empty and I print gs.addInfoMessage(producer.u_portfolio_list.toString()) it returns 'undefined' so I have even tried if (producer.u_portfolio_list.toString() == "undefined").
In all these cases the code enters the IF statement and prints the ', '.
Any advice...even if I'm missing something really stupid would be greatly appreciated as this is just doing my head in and wasting sooo much time.
Thanks.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 03:15 PM
Can you try
var clients = "";
clients = producer.u_primary_client.getDisplayValue();
if (producer.u_portfolio_list)
{
clients += ", " + producer.u_portfolios_list.getDisplayValue();
}
current.u_clients = clients;
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 03:33 PM
That passes by the IF and omits the comma if the field is empty but it also passes the IF statement when there are values selected in the list selector and then doesn't print the , and what has been selected in the list collector.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 03:40 PM
Ok. This should work
var clients = "";
clients = producer.u_primary_client.getDisplayValue();
if (producer.u_portfolio_list.toString().length>0)
{
clients += ", " + producer.u_portfolios_list.getDisplayValue();
}
current.u_clients = clients;
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 03:50 PM
It does the same, ignores the IF statement when the list collector has no value and also ignores it when it has values. I also tried
if (producer.u_portfolio_list.length>0)
without the toString() and that didn't work either.