Re: Validation of an array field using format Control (1057 Views)
Reply
Regular Advisor
ArpitAggarwal07
Posts: 104
Registered: ‎09-10-2013
Message 1 of 12 (1,115 Views)
Accepted Solution

Validation of an array field using format Control

Hi All

 

I have a requiremnet to validate an array  field : "assets". This field needs to validated against device table .

I have written the validations, but it is working when there is single data in the array field, else it is throwing validation errors for correct data as well .

 

Can I use for loop in queries ??

 

Thanks in advance for you help .

Regards

AA

Honored Contributor
Vadim Gorda
Posts: 5,861
Registered: ‎11-10-2008
Message 2 of 12 (1,112 Views)

Re: Validation of an array field using format Control

I would have done it with JS using loop inside of it. Then the result of that JS you can use on your validation tab of fc

Honored Contributor
John Stagaman
Posts: 3,523
Registered: ‎07-13-2007
Message 3 of 12 (1,085 Views)

Re: Validation of an array field using format Control

The easiest way to validate an array is to use a match field validation in data policy. So if your field is assets, for that field in the data policy record add "logical.name" to the match field column and "device" to the match table column. 

----------------------------------------------------
Kudos - what, where, how, and why
Want Good Answers? Ask Good Questions...
Regular Advisor
ArpitAggarwal07
Posts: 104
Registered: ‎09-10-2013
Message 4 of 12 (1,077 Views)

Re: Validation of an array field using format Control

Hi John .. I have to validate istatus and type field.. Hence I do not think it will be possible through datdict record .

Honored Contributor
Vadim Gorda
Posts: 5,861
Registered: ‎11-10-2008
Message 5 of 12 (1,075 Views)

Re: Validation of an array field using format Control

Hello,

I think that it will be much more easier to suggest solution if you will describe your exact task.


Please write what must be validated over what. Do you need to validate data to 2 possible tables?

Regular Advisor
ArpitAggarwal07
Posts: 104
Registered: ‎09-10-2013
Message 6 of 12 (1,067 Views)

Re: Validation of an array field using format Control

Hi Vadim

 

I have to validate the asset field (array type) in cm3r table to two field in device table : istatus and type

 

istatus~="Out oF Stock"

type~="Application"

 

I wrote queries , calculation,validation which works perfectly fine when there is single data in array, however in case of multiple data the validation fails ..

 

I am having difficulty in validating the data in array field..

Frequent Advisor
mpatrikov
Posts: 36
Registered: ‎09-11-2013
Message 7 of 12 (1,064 Views)

Re: Validation of an array field using format Control

Hi,

 

Can you post screenshots on what you have done so far and give us an example as well so we can help you further?

 

Thank you!

 

Best Regards,

Miro

Regular Advisor
ArpitAggarwal07
Posts: 104
Registered: ‎09-10-2013
Message 8 of 12 (1,061 Views)

Re: Validation of an array field using format Control

Attached is the explanation with screenshots

Honored Contributor
Vadim Gorda
Posts: 5,861
Registered: ‎11-10-2008
Message 9 of 12 (1,057 Views)

Re: Validation of an array field using format Control

[ Edited ]

Hello,

you can try to use index() but I strongly won't recommend that as it will give additional load on the productivity for the array field.

 

From current vision i would have written a short script which will run through all elements of the array (loop) and check if the meanings which you are trying to avoid are present there.

 

for example

var ii=0;

length=vars.$file.asset.length();

for(ii=0;ii<length;++ii){

var develement= new SCFile("device");

var rc = develement.doSelect("logical.name=\""+vars.$file.asset[ii]+"\"");

  if(rc==RC_SUCCESS && develement.istatus=="Out oF Stock" && develement.type=="Application"){

vars.$checkvariable=true;

}

}

Based on that variable  you can cut validation which you need

 

 

as additional question to cover the logic which you need  please clarify that - you want to check for each element of the asset array its status  and type?

Advisor
AlexRussell
Posts: 11
Registered: ‎10-31-2011
Message 10 of 12 (1,045 Views)

Re: Validation of an array field using format Control

Would this work:

make the query only select assets that have the status and other field set to the correct values, and make the query count, ie set the comment to "count".

 

if the count returned by the query is equal to the count of assets in the array then pass the validation. If the number is different fail it.

 

Doesn't tell you exactly why it failed, but is quick and easy.

 

A more complex way is to loop and do a search with Javascript or rad code for each asset, if errors are found add them to a string, and set an error variable. Have the validation just check the error vairiable and display the string set by the validation javascript/calcualation.

Regular Advisor
ArpitAggarwal07
Posts: 104
Registered: ‎09-10-2013
Message 11 of 12 (1,026 Views)

Re: Validation of an array field using format Control

Thanx Vadim .. It has resolved my issue... Thank you again ..

Honored Contributor
Vadim Gorda
Posts: 5,861
Registered: ‎11-10-2008
Message 12 of 12 (1,008 Views)

Re: Validation of an array field using format Control

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.