Forum Discussion
Hi
I was using another approach by hooking the method to on form populated event of the form
Steps to be followed are
Step 1: Create a Javascript method and add below code
var innovator = new Innovator();
var action = "edit";
if(aras.isLocked(parent.item))
{
action = "update";
}
var parentField = getFieldByName("score_1");
parentField.getElementsByTagName("input")[0].disabled = true;
var rs = innovator.newItem("Performance_SelfScore", "get");
rs.setProperty("source_id", document.thisItem.getProperty("id"));
rs.setAttribute("Select", "self_score");
rs = rs.apply();
if (rs.isError())
{
return rs;
}
var sum_self_score = 0;
var self_score = 0;
for (var i = 0; i < rs.getItemCount(); i++)
{
self_score = rs.getItemByIndex(i).getProperty("self_score");
sum_self_score = sum_self_score + self_score;
}
var currentScore = document.thisItem.getProperty("score_1","");
if(currentScore != sum_self_score)
{
var Self_Eval = innovator.newItem("Performance_Self_Evaluation", action);
Self_Eval.setAttribute("id", document.thisItem.getProperty("id",""));
Self_Eval.setProperty("score_1", sum_self_score);
var Self_Eval = Self_Eval.apply();
aras.uiReShowItem(parent.thisItem.getID(), parent.thisItem.getID());
}
step 2: Add this method to Performance_Self_Evaluation form populate event
Test and let me know if it works
Thank You
Gopikrishnan R
- Mavis5 years agoIdeator I
hi ,Gopikrishnan
First of all, thank you for your reply!
I tested this code, but I get the error message "parent.thisItem is undefined" or "menuFrame.populateAccessMenu is not a function".
Later I changed the
aras.uiReShowItem(parent.thisItem.getID(), parent.thisItem.getID());
changed to
"aras.uiReShowItem(document.thisItem.getProperty("id"), document.thisItem.getProperty("id"));
There is still the error message "menuFrame.populateAccessMenu is not a function"...And it also seems to cause infinite loops when placed under this event
- Gopikrishnan5 years agoIdeator I
Hi Mavis
Can you try below steps
Remove all the methods and event added as per my previous suggestion.
Step 1: Create new C# Server Method and add below code
Innovator inn = this.getInnovator();
int currentValue = Int32.Parse(this.getProperty("score_1"));
Item relItm = inn.newItem("Performance_SelfScore", "get");
relItm.setProperty("source_id", this.getID());
relItm.setAttribute("select", "self_score");
relItm = relItm.apply();
int sum_self_score = 0;
for (int i = 0; i < relItm.getItemCount(); i++)
{
sum_self_score = sum_self_score + Int32.Parse(relItm.getItemByIndex(i).getProperty("self_score","0"));
}
if(currentValue != sum_self_score)
{
Item updateItem = inn.newItem("Performance_Self_Evaluation", "edit");
updateItem.setAttribute("id", this.getID());
updateItem.setProperty("score_1", sum_self_score.ToString());
updateItem = updateItem.apply();
}
return this;Add this method to Performance_Self_Evaluation item type server Events OnAfterUpdate event
Thank You
Gopikrishnan R
- Mavis5 years agoIdeator I
hi,Gopikrishnan
Thanks again for taking the time to help me!
You wrote the method in C# ,it works!
I have also rewritten the original VB code I wrote
plus determine if the current score_1 is the same as the previous score_1
It will not loop infinitely and it will run!Also, about the code you wrote in the previous paragraph (Javascript)
I will
"aras.uiReShowItem(parent.thisItem.getID(), parent.thisItem.getID());"
change to
"document.thisItem.setProperty("score_1", sum_self_score);
handleItemChange("score_1",sum_self_score);"
It works too!Thank you!!