Adding an Email Address to a Contact using CRMScript when the contact is saved

Hi,

Many years ago I wrote a SuperOffice Windows script which, when editing a contact would add the company email address as the contact's email address, if the contact did not have one of their own.  This because Marketing and eMarketeer used the contacts email address instead of the company.

The customer is now using web more, and needs the same script.  I have basically got it working, but the way I have done it does not refresh the screen when the email address is added.

Firstly I used the Before Save event and used this code.

NSEntityElement[] emails = contact.GetEmails();

if (emails.length() > 0)
{
 NSEntityElement email1 = emails[0];
 ev.setOutputValue("PersonEntity.Emails[0].Value", email1.GetValue());
}

But this would update the first email address if one were present, but would fail if the contact did not have an email address.

I then tried on the After Save event and used this code (code did not work using Before Save).

NSEntityElement[] emails = contact.GetEmails();

if (emails.length() > 0)
{
 NSEntityElement[] companyEmail;
 companyEmail.pushFront(emails[0]);

 NSPersonAgent personAgent;
 NSPersonEntity person = personAgent.GetPersonEntity(personId);
 person.SetEmails(companyEmail);
 personAgent.SavePersonEntity(person);
}

This does work, but you cannot see the email unless you refresh the page.

So my two questions are:

Is this the best way to achieve this?

Is there a way of forcing a refresh of the web page after the email address have been added?

Many thanks,

Trevor

RE: Adding an Email Address to a Contact using CRMScript when the contact is saved

Hi Trevor,

Have you tried navigating to that person after the save? Haven't tried this, but something like:

EventData ed;
ed.setNavigateTo("soprotocol:person.main?person_id=personId);

Hope this helps!

Av: Tony Yates 14. jun 2019

RE: Adding an Email Address to a Contact using CRMScript when the contact is saved

Hi Tony,

That's perfect, thank you.

Trevor

Av: Trevor Sharp 14. jun 2019