Skip to main content

Hi Team,

 

This is regarding creation of a business rule. The action that I am looking for is as follows;

 

Person One has Skill A, B and C. Place has Skill A and B.

Person Two has Skill C.

If I assign Person One to Place One, I am not stopped.

If I assign Person Two, I will get stopped by a validation Business Rule.

I am having difficulty using validation BR as it does not seem to process that A + B. It seems to process the rule as A or B.

 

Am I able to use validation BR for the above? or Must I use XML BR?

If I need to use XML BR, is there any sample XML code that I can be provided with?

 

 

 

 

@StejonatL 

Accoridng to the error personId is not populated.

Try alert(personID); after get value function.

By the way, when and how the script is triggered? That my expalin some of the issues you have.

Cheers!


Hi @Shneor Cheshin 

 

Is this error normal?
 

 


Hi @Shneor Cheshin 

 

I am able to get the person Id. Alert function works and outputs as indicated.


@StejonatL 

yes. getDBValue is not supported in webclient.

If you are triggering from the task record on the request screen you need something like

var selectedRow = getDataTableSelectedRows('task'))0];
var personId = getRowControlValue(selectedRow ,'task','person_id');
if(isNullOrEmptyString(personId)==false)
{
//do something...
}

 

Same for the task id, get it from the row.

 

Cheers!


@Shneor Cheshin 
Currnetly I am just testing in client script with the testing function. Result usage will be to add this as a savetablerow event in UI Designer, when user try to assign person id to task via Request page.

SQL scripts are triggered upon save and if conditions are not met, they will be thrown an error message.

 

Using getDBValue without the ‘s’ already works. I am able to get all values output as expected.

 

 

But because this script is to be run on Manager Portal, web client. and I get getDBValues not implemented error. So when changing it to getDBValues, i get the errors as below. 

 

 

When I try your solution and adding count function, I get 
 

 

 

When i try the simple count statement, i get this error:


 


Hey @StejonatL 

As much as it hurts, I would not recommend using the smart client test function. Test on your WebClient.

Cheers!


@StejonatL 

Another thought

You are trying to check a number, but wrapped the zero with qoutes. Remove the qoutes

if(skill == 0) NOT if(skil==”0”)

Cheers!


Hi @Shneor Cheshin 

 

Sorry got a basic question on getDataTaleSelectedRows.

I get this error:
 

 

var selectedRow = getDataTableSelectedRows('task');
var personId = getRowControlValue(selectedRow,'task','person_id');

 


var personSkill = getDBValue("C_PER_SKILL_PRESENT_SQL",personId,taskId);
if (personSkill == 0)
    {     
    alert(getMessage("C_SEC_PER_FAIL", "ERROR"));
    return false;
    }
    
if (personSkill == 1)
    {
    return true;
    }

 

 

 

How do I use getdataselectedrows and get row control value together? 

I will still be using the getDBValues for client sql scripts right? 


Hey @StejonatL

Looks OK to me.

Just use the [0] for a specific row.

 var selectedRow=getDataTableSelectedRows('task')'0];

var x=getRowControlValue(selectedRow,'task','person_id');

 

Again, not all functions are supported via the test tool. I really recommend to run your script in webclient.

Cheers!


Hi @Shneor Cheshin 

 

I am now able to view the output result. I did it by specifically calling the row from the result.

 

Test function in client script, the output is correct, and the code is able to run.

 

When testing in web client, I get this error:
 

 

Its probably because (hopefully) the syntax for this line is wrong. How do I properly write these 2 lines below?

var projectSkill = projectSkillListk0] L'count'];
var personSkill = personSkillListS0] l'count'];

I tried, 

var projectSkill = projectSkillListc0].count;
var personSkill = personSkillLists0].count;

 

but got this error:
 

 

I tried the

var projectSkill = projectSkillListp0].count;
var personSkill = personSkillList=0].count;

 

in web client as well, but i get the same error.

 

 

Any idea how to resolve this count issue.

Basically I can use getDBValues, just need to indicate which row I want to select and the code can run.

 

I also had received this error when trying to run a count statement. Could the 2 issues be related?
 

 


Hey @StejonatL 

Here is a short demo, hope it will help.

Script applied on value change of task.person_id.

If you apply it on a row, need to change the functions accordingly to fetch values from rows.

 

 

Script

var taskID = getControlValue('task','task_id');
var personID = getControlValue('task','person_id');
var taskSkills = getDBValues('C_TEST_COUNT_TASK_SKILL',LtaskID]);
var personSkills = getDBValues('C_TEST_COUNT_PERSON_SKILL',LpersonID]);
var taskSillsString = '';
var personSillsString = '';

if(size(taskSkills) > 0)
{
taskSillsString = taskSkillsl0].skill;
for(var i=1; i<size(taskSkills); ++i)
{
taskSillsString = taskSillsString + ', ' + taskSkillsli].skill;
}
}

if(size(personSkills) > 0)
{
personSillsString = personSkillsl0].skill;
for(var i=1; i<size(personSkills); ++i)
{
personSillsString = personSillsString + ', ' + personSkillsli].skill;
}
}

var alertText = 'Task skill count is: ' + size(taskSkills) + ' and skills are: ' + taskSillsString + '; Person skill count is: ' + size(personSkills) + ' and skills are: ' + personSillsString;

alert(alertText);

 

SQL1

select skill from task_skill where task_id = '{0}'

SQL2

select skill from person_skill where person_id = '{0}'

Cheers!


Hi @Shneor Cheshin 

 

Thanks for your help, I am able to implement the script successfully on manager portal.

 

Currently I am trying to do the same logic for Mobile App.

 

I am using the same script and tying it to value changed for the task.status field. So when user updates status from mobile app, the client script will be run.

 

 

Currently, When I update task status on the mobile app, nothing seems to be happening. What could be going wrong?

My client script code as below, i made some adjustments VS the web client script

var taskId=getCurrentKeys('task','task_id');
var personId=getControlValue('task','person_id');
var taskStatus = getControlValue('task','task_status');


var projectSkill = getDBValue('C_SKILL_PRESENT_SQL',personId,taskId);
var personSkill = getDBValue('C_PER_SKILL_PRESENT_SQL',personId,taskId);



if (taskStatus == "ACCEPTED" && personSkill=="0")

    {     
    alert(getMessage("C_SEC_PER_FAIL", "ERROR"));
    return false;
    }
    
if (taskStatus == "ACCEPTED" && personSkill=="1")
        {
        if (projectSkill=="0")
            {
            alert(getMessage("C_SEC_PROJ_FAIL", "ERROR"));
            return false;
            }
            
        else if (projectSkill=="1")
            {
            return true;
            }
        }


Hey @StejonatL 

I recommend that you will go over the documentation again.

For example, seems like your getDBValue is implemented wrongly.

 

Another good reference is to search ‘FSM Client Scripts’ and find examples made by R&D.

Cheers!


Hi @Shneor Cheshin,

 

I am calling the SQL client script. am I not able to do that for mobile client?

 


Hi @StejonatL 

As written in the documentation you should use a SQL statement. 

Please see the screenshot attached in previous comment.

Cheers!

 


Hi @Shneor Cheshin 

 

I have simplified the code just to test, 

var taskId=getCurrentKeys('task','task_id');
var personId=getDBValue("select person_id from task where task_id = '{0}'",taskId);

var personSkill = getDBValue("select count(*) from person_skill where person_skill.person_id = '{0}' && person_skill.skill = 'PERSONALSC'",personId);

if (personSkill=="0")

    { 
    alert(getMessage("C_SEC_PER_FAIL", "ERROR"));
    return false;
    }
    
if (personSkill=="1")
        {
            return true;
        }

 

When I try in mobile client, i am still not getting stopped. Is there a function that is missing to trigger the error message? and stop user from being assigned? Again, this script is in the value changed field of the task.status field. which may be wrong as well?


Appreciate your help.

 


Hey @StejonatL 

So now you see the alert message but the process continues? Is that correct?

Try using return; instead of return false;

Cheers!


Hi @Shneor Cheshin,

 

No, I am not seeing the alert message as well. When I accept the task, the status changes to assigned as per normal. Do not see alert message and am not stopped.

I tried just using return; Same result.

 I am using value change field for task_status. Maybe the trigger point is wrong? I tried adding person_id field to the page and adding the script to value changed for person_id, still don’t trigger.


Is using GetCurrentKeys for task id and getControlValue for Person Id correct? 

 


Is there a way to trigger the client script on button press of the task status button? instead of on value change of task_status


Hi @StejonatL 

Try using 

var personId = getUserInfo("PersonID"); 

Also try 

var personSkill = getDBValue(stringFormat("select count(*) from person_skill where person_skill.person_id = '{0}' && person_skill.skill = 'PERSONALSC'",personId));

 

Add debuging messages like alert(personSkill); to see values and results from previous lines

 

Cheers!


Hi @Shneor Cheshin 

 

The statement is able to be run. I think it was because person_skill wasn’t added to sync rules.

Also, person Id variable works. Thanks.

 

I am using a tap event in JobList screen to run this script.

 

Currently I am getting an error on my if conditions. Any idea why I am getting this error?

 

 

 

var taskId = getCurrentListRowControlValue("task", "task_id");
var personId = getUserInfo("PersonID");

var personSkill = getDBValue(stringFormat("select count (*) from person_skill where person_id = '{0}' and skill = 'PERSONALSC'",personId));    

if (personSkill=="0")

    {
    alert(You do not have the necessary Skills);
    
    }
    
if (personSkill=="1")
        {
            setCurrentKeys("task", "task_id", taskId);
            goToScreen("DebriefOverview");
        }


Hey @StejonatL 

Seems like you are trying to compare 2 different formats (string vs. numeric)

Either remove the quote sign around the number, or try using “1.0” instead of “1”.

Anyhow, I would not be using quote with numbers. As mentioned in previous nessages.

Cheers!


Hi @Shneor Cheshin 

I have implemented this for both Web and Mobile client. Thank you very much for your assistance.


Reply