Service Manager / Service Center Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Validation of an array field using format Control

SOLVED
Go to Solution
Valued Contributor

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

11 REPLIES
Honored Contributor Honored Contributor

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 Honored Contributor

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...
Valued Contributor

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 Honored Contributor

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?

Valued Contributor

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

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

Valued Contributor

Re: Validation of an array field using format Control

Attached is the explanation with screenshots

Highlighted
Honored Contributor Honored Contributor

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

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.

Valued Contributor

Re: Validation of an array field using format Control

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

Honored Contributor Honored Contributor

Re: Validation of an array field using format Control