Is there a better way to get the personId of the current contact than using getCgiVariable("personId")? Lately this has become unstable and often returns the personId of a previously viewed user.
The following script is run when a user clicks a button on either a contact card or a ticket/request. So what I need in the end is the x_personid, which is a custom field on person.
#setLanguageLevel 4;
Integer personId = getCgiVariable("personId").toInteger();
if (personId.isNull() == true || personId < 1)
{
setVariable("url", getProgramBlogic() + "&action=doScript&includeId=close");
}
String externalPersonId;
SearchEngine se;
se.addField("person.x_personid");
se.addCriteria("person.person_id", "Equals", personId.toString());
if(se.select() > 0)
externalPersonId = se.getField(0);
if(externalPersonId.toInteger()>0)
setVariable("url", "https://bn.app.local/Customer/Link/" + externalPersonId);
else
setVariable("url", getProgramBlogic() + "&action=doScript&includeId=close");
Alle Svar (3)
Hi Snorre,
Get the active user, then traverse to get the users person id.
// get current user associate ID
User a = getActiveUser();
Integer associateId = a.getValue("associateId").toInteger();
Integer personId;
// get person ID from associate ID
NSAssociateAgent aa;
NSAssociate associate = aa.GetAssociate(associateId);
personId = associate.GetPersonId();
printLine("Person ID from associate: " + personId.toString());
// OR
SearchEngine se;
se.addField("associate.person_id");
se.addCriteria("associate.associate_id", "OperatorEquals", associateId.toString());
se.execute();
se.first();
personId = se.getField(0).toInteger();
printLine("Person ID from SE: " + personId.toString());
Best regards.
Hi Snorre,
I think perhaps you didn't want to the personId of the current associate, but rather the current person in CRM?
You say that getCgiVariable("personId") is unstable. That's not our experience. I think we need to look into your button setup. From your text it seems like you mean that when you click the button the script is called with the wrong personId in the URL.
Can you share how you have configured the button?
Hi Frode
getCgiVariable("personId") is definately unstable on the latest cloud version of crm. After about 30-45 min it starts returning the personid of a previously opened customer. There is some kind of strange caching going on here.
I got help from Simen(SuperOffice) creating a workaround where we use getCgiVariable("ticketId") and from there navigating to the connected customer. We are testing this now and so far it looks better.
String ticketId = getCgiVariable("ticketId");
String personId = getCgiVariable("personId");
String externalPersonId;
String navigateUrl = getProgramBlogic() + "&action=doScript&includeId=close";
String ticketPerson;
if(ticketId.toInteger() > 0) {
SearchEngine seTicket;
seTicket.addField("ticket.cust_id");
seTicket.addCriteria("ticket.id", "Equals", ticketId);
if(seTicket.select() > 0) {
ticketPerson = seTicket.getField("ticket.cust_id");
}
}