Hello,
I am not the most experienced person regarding CRMscript, I am sorry for the newbie mistakes.
I am trying to update the Visible For field, but it seems that the values from the Even Data are not the correct.
ED keeps returning database values rather than the actualy ED values.
For example if the Visible for is set to me, and then I change it to someone else, it will change to that person in the UI, but when looking up the field in ED, I get myself, not that person.
Considering this "bug" I've looked for a way to change it "After" saving the sale rather than "Before" trigger, but it seems that I am unable to save the array[].
I've also tried to ed.SetOutput but I can't seem to be able to change the Visible for value whe using the "Before saving" trigger.
Is there something I am missing or doing wrong?
Any help would be grately apreciated.
#setLanguageLevel 3;
//Event Data
EventData ed = getEventData();
/*---------------------------------------------------------------------------------------------*/
//Get required fields from ED
String saleVisibleFor = ed.getInputValue("SaleEntity.VisibleFor.length");
String saleVisibleForId = ed.getInputValue("SaleEntity.VisibleFor[0].VisibleId");
String saleVisibleForValue = ed.getInputValue("SaleEntity.VisibleFor[0].DisplayValue");
/*---------------------------------------------------------------------------------------------*/
//Get Sale
Integer sale_id = ed.getInputValue("SaleEntity.SaleId").toInteger();
NSSaleAgent saleAgent;
NSSaleEntity saleEntity = saleAgent.GetSaleEntity(sale_id);
//GetVisibleFor
NSVisibleFor[] visibleFor = saleEntity.GetVisibleFor();
//GetVisibleFor Values
Integer visibleForId = visibleFor[0].GetVisibleId();
String visibleForIdString = visibleForId.toString();
String visibleForValue = visibleFor[0].GetDisplayValue();
/*---------------------------------------------------------------------------------------------*/
//Confidential sale
//3164
visibleFor[0].SetVisibleId(3164);
saleAgent.SaveSaleEntity(saleEntity);
ed.setMessage("saleVisibleFor = "+saleVisibleFor+"\n"+
"saleVisibleForValue = "+saleVisibleForValue+"\n"+
"saleVisibleForId = "+saleVisibleForId+"\n"+
"-----------------\n"+
"visibleForIdString = "+visibleForIdString+"\n"+
"visibleForValue = "+visibleForValue+"\n"
);
All Replies (2)
You can set the Visible For on the sale entity like this;
NSSaleAgent saleAgent;
EventData eventData = getEventData();
Integer saleId = decodeDBValue(eventData.getInputValue("SaleEntity.SaleId")).toInteger();
NSSaleEntity saleEntity = saleAgent.GetSaleEntity(saleId);
NSVisibleFor[] visibleForRules;
NSVisibleFor visibleForRule;
visibleForRule.SetVisibility(NSVisibility.Group); // associate/group
visibleForRule.SetVisibleId(1234); // id of the associate/group
visibleForRules.pushBack(visibleForRule);
saleEntity.SetVisibleFor(visibleForRules);
saleEntity = saleAgent.SaveSaleEntity(saleEntity);
Thank you David!
I've also adapted to make it work for documents.