Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Getting Street Zipcode by CRM Script from inputValue

Hello,

how is it possible to get the Street Zipcode in CRM Script from the Input Value?

I already traced it down in the Debugger but I don't know how to access the right value with CRM Script

RE: Getting Street Zipcode by CRM Script from inputValue

EventData ed = getEventData();

Integer addressesLength = ed.getInputValue("ContactEntity.Address.LocalizedAddress.length").toInteger();

for (Integer i = 0; i < addressesLength; i++)
{
  Integer addressLength = ed.getInputValue("ContactEntity.Address.LocalizedAddress[" + i.toString() + "].length").toInteger();

  for (Integer j = 0; j < addressLength; j++)
  {
    String addressName = ed.getInputValue("ContactEntity.Address.LocalizedAddress[" + i.toString() + "][" + j.toString() + "].Name");
    String addressValue = ed.getInputValue("ContactEntity.Address.LocalizedAddress[" + i.toString() + "][" + j.toString() + "].Value");
    
    if (addressName.equals("StreetZipcode"))
    {
      //Do your stuff
    }
  }
}
Af: Dennis Pabst 14. sep 2021

RE: Getting Street Zipcode by CRM Script from inputValue

Hi,

If you're only after the input value, you should be able to use the "new" Simple Address Object, to be able to get the zipcode value directly, without having to loop through the LocalizedAddress object.

Example:

String companyPostalAddress1 = ed.getInputValue("ContactEntity.Address.Postal.Address1");
String companyPostalAddress2 = ed.getInputValue("ContactEntity.Address.Postal.Address2");
String companyPostalAddress3 = ed.getInputValue("ContactEntity.Address.Postal.Address3");
String companyPostalCity = ed.getInputValue("ContactEntity.Address.Postal.City");
String companyPostalZipcode = ed.getInputValue("ContactEntity.Address.Postal.Zipcode");
String companyPostalCounty = ed.getInputValue("ContactEntity.Address.Postal.County");
String companyPostalState = ed.getInputValue("ContactEntity.Address.Postal.State");

Though, there is a caveat with using this method if you want to compare the value before and after changes in the trigger. Because the changes isn't saved in this variable, it keeps the inputValue. To be able to get the changes applied to zipcode in a trigger, you will still have to use the LocalizedAddress object, unfortunately.

You can see the below forum posts where this is discussed and gets somehow clarified by Tony and Christian in RnD.

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/address-in-eventdata-is-inconsistent/

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/crmscript-copy-contact-postaladdress-to­-person-address/

Variable Info
To be able to see the full list of available EventData variables in a trigger, you could dump the EventData-object to the log as part of the trigger code. I often use this to be able to see what I can work with.

//Get Eventdata from trigger
EventData ed = getEventData();
log(ed.getInputValues().toJson());

Helper Libs
Frode have also built a library of helper libs, where there is one focused on helping out with Addresses, but I didn't find any helper methods in that lib that was especially helpful for working with these type of EventData-objects, as I needed to compare before and after state of the zipcode value, so I ended up with writing my own extraction methods.

Dennis posted code seems to be able to solve this extraction quite effectively. But if you ONLY need to get the inputvalue of the zipcode, you should be able to use the Simple Address Object instead, to get the value directly without necessary field-looping.

https://github.com/SuperOffice/CRMScripts/blob/master/Library/lib-address.crm

/Marcus

Af: Marcus Svenningsson 28. sep 2021