How to validate if list collector has no value in record producer script

Dedrei L_
Tera Contributor

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.

13 REPLIES 13

I am pretty sure this will work.

producer.u_portfolio_list.toString().length

 

Can you add some logs to check

 

var clients = "";
clients = producer.u_primary_client.getDisplayValue();
gs.addInfoMessage('++++Portfolio List++++'+producer.u_portfolio_list);
gs.addInfoMessage('++++Portfolio List Length++++'+producer.u_portfolio_list.toString().length);
if (producer.u_portfolio_list.toString().length>0)
	{
gs.addInfoMessage('+++++inside the If statement+++++');
		  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.

Hi Sanjiv, thanks for your help.

My sincere apologies.  Your initial suggestion works.  When I tried that I had a typo in the variable name: u_portfolio_list instead of u_portfolios_list......and I think some of the others I mentioned in my question will work too.  I suspected that it was something silly I'm missing because the code made sense.

Thanks for your time!

 

 

Dedrei L_
Tera Contributor

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.

dvp
Mega Sage
Mega Sage

Can you try this

var clients = "";
clients = producer.u_primary_client;
if (producer.u_portfolio_list)
	{
		  clients += ", " + producer.u_portfolios_list;
	}
current.u_clients = clients;

 

Dedrei L_
Tera Contributor

Thanks for your suggestion but that ignores the IF statement in both cases too, if it has value and if it has no value.  This also prints the primary client's sys_id and not the display name.