We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

Before/After saving relation in trigger (CRMScript)

Hi

 

When deleting a relation no of the triggers Before /After saving relation is fired. they work fine when adding a new relation.

Is it something that I'm doing wrong or?

/Rasmus

RE: Before/After saving relation in trigger (CRMScript)

Hi,

Could you elaborate at bit more exactly what you are trying to achieve?

Von: Michel Krohn-Dale 22. Jun 2020

RE: Before/After saving relation in trigger (CRMScript)

Hi

I need to sync the relations from SuperOffice to a database (We use these relations in other systems).
I have created a "Sales: After saving relation" trigger in CRMScripts 

Script Start

#setLanguageLevel 3;

EventData ed = getEventData();
Map inputs = ed.getInputValues();
NSContactAgent newNSContactAgent

String MainOffice = ed.getInputValue("ContactRelationEntity.SourceContactId");
String SubOffice = ed.getInputValue("ContactRelationEntity.DestinationContactId");

NSContactEntity getMainNSContactEntity = newNSContactAgent.GetContactEntity(MainOffice.toInteger());
NSContactEntity getSubNSContactEntity = newNSContactAgent.GetContactEntity(SubOffice.toInteger());

String MainOrgNr = getMainNSContactEntity.GetOrgNr();
String SubOrgNr = getSubNSContactEntity.GetOrgNr();

Script end

This scripts post the MainOrgNr and SubOrgNr to a webservices.

This only works when I create a relation in SuperOffice. If I delete a relation then the trigger is not fired.

The quest is how do I setup a post when a relation is deleted in SuperOffice?

/Rasmus

Von: Rasmus Gamskjær Andersen 22. Jun 2020

RE: Before/After saving relation in trigger (CRMScript)

I can be wrong, but I don't think we have any triggers for delete-events. I have the same problem for sales that I want to track the deletion of as they are connected to a project with UDFields that I want to recalculate. But Michel might have some better insight in this.

I assume that it is related to some existing architecture where deleted items isn't cached in the internal EntityAfterDeleteEvent, so there isn't much info to add in the event, apart from maybe the id of the deleted item.

In my case I would have needed the related project id to be able to effectively recalculate the correct project. I will solve that using a Batch Script Framework that is scheduled. Mainly because I need it also for other things.

It would have been nice though to have triggers for delete-events that also included some cached entity information to be used for different operations.

There is a "sales.delete" web hook event that could be subscribed to. But I think that the notification only contains the id of the sale, so it will not solve my specific problem, as I would also need the related project id.

In your specific case, there doesn't seem to exist a web hook for the relations entity.

I don't think there is a event available in CRMScript that can be used. There might be an event using a NetServer Event, but I'm not sure if that is available in some way in Online if you create a custom app.

Please, read the articles below to get some insight in the different behaviour for different event methods.

Scripting NetServer Services
https://community.superoffice.com/en/content/content/webclient/Scripting-in-the-NetServer-World/

Web Hooks Articles:
https://community.superoffice.com/en/content/content/netserver-sdk/netserver-8.x/superoffice-webhooks/

https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/creating-webhooks-in-crmscript/

https://community.superoffice.com/en/developer­/forum/rooms/topic/superoffice-product-api-group/crm-online-application/person-event-for-bulk-update/

Article related to different types of events i SO:
https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/crm-web-application/how-to-catch-crud-operations-performed-by-built-in-rest-api/

/Marcus

Von: Marcus Svenningsson 23. Jun 2020

RE: Before/After saving relation in trigger (CRMScript)

Hi,

What can be somewhat confusing is understanding exactly how the different triggers work, in CRM they are closely connected to "dialogs" (Contact card, Company card, Sales card, Project card, Appointment dialog etc) . For instance if you complete an appointment from a archive by right clicking, it will not fire any trigger.

In the case of deleting relations this behaves slightly different, it is possible to delete multiple relations simultaneously and only a confirmation message box is triggered. 

I would think that webhooks would be the way to go, but it does not look like relations are supported.

Unfortunately I do not have any good solutions for this scenario currently, perhaps some other API gurus can provide some input.

Von: Michel Krohn-Dale 23. Jun 2020

RE: Before/After saving relation in trigger (CRMScript)

The only way to get notified when a relation is deleted today is using NetServer Service script events. Marcus posted a link to the article about these (first link), and is only available for onsite installations.

The event would have to be for the RelationAgent.DeleteContactRelation method. 

Best regards.

Von: Tony Yates 23. Jun 2020