What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi all,

What have to be done to get a ISoftTriggerPlugin to work?
Have tried register it in the DynamicLoad section in web.config

    public class AddressSoftTrigger : ISoftTriggerPlugin
    {
        public void Initialize(SoftTrigger softTrigger)
        {
            softTrigger.SubscribeOnPreChange(7, OnChange);
        }

        public void OnChange(SoTable table, SqlType sqlType, int primaryKey, PrivateSave privateSave, SqlCommand command)
        {
            using(var sw = new StreamWriter("c:\\temp\\softtriggerlog.txt"))
            {
                foreach(var select in command.GetSelect())
                {
                    sw.WriteLine($"{select.SqlType.ToString()} - {select.ReturnFields.ToString()}");
                }
            }
        }
    }

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Um, what is ISoftTriggerPlugin supposed to be used for? Is it like the C# version of CRMScript Triggers?

Av: Frode Lillerud 4. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi Frode,

Tony mentions ISoftTriggerPlugin in this thread.

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/

 

Av: Patrik Lindholm 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi,

Frode=>

We are searching for an answers of the following qestions: (also at the en in the thread that Patrik submitted:link)

1. is it possible to detect changes in a Service  Extra Table by webhooks, just like for contacts/persons?

2. If yes how is it done? (Soft trigers sounds like a possible way but please share knowledge if there are better ways)

3. If no, will SuperOffice be able to support detection of changes by webhooks in some upcoming builds? 

 

/Anders

Av: Anders Larsson 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi!

SoftTriggers have been around for many years. I discussed them in an Expander World Session in 2007/2008? 

All plugins are discovered with attributes. So I think the only thing missing from Patricks example is the attribute. 

If there is a physical table and it is registered with the dictionary, you can access it by name. Here is an example registering for notifications when the contact table has inserts/updates/deletes:

using SuperOffice.Data;
using SuperOffice.CRM.Data;
using SuperOffice.Data.Dictionary;
using SuperOffice.Data.SQL;

[SoftTriggerPlugin(Name)]
public class WebhookSoftTriggerPlugin : ISoftTriggerPlugin
{
    public const string Name = "MySoftTriggerPlugin";

    public void Initialize(SoftTrigger softTrigger)
    {
        // Don't register triggers if not logged in yet
        var db = SoDatabase.GetCurrent();
        if (db != null && db.IsInitialized)
        {
            var dict = db.Dictionary;
            softTrigger.SubscribeOnPostChange(dict[DBC.Contact].TableNumber, OnChanged)
        }
    }

    private void OnChanged(SoTable table, SqlType sqlType, int primaryKey, 
        PrivateSave save, SqlCommand orgSqlCommandInner)
    {
        switch (sqlType)
        {
            case SqlType.IsInsert:
                break;
            case SqlType.IsUpdate:
                break;
            case SqlType.IsDelete:
                break;
            default:
                break;
        }
    }
}

Hope this helps!

Av: Tony Yates 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Thanks Tony,

It will help.

Best regards

Patrik

Av: Patrik Lindholm 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

If you want to fire off a webhook from your soft trigger, you will need to do something similar to what Contact/Project/etc do:

 

var dispatcher = WebhookManager.GetCurrent();
string entityName = GetEntityName(table, save);
IDictionary<string,object> changes = GetChanges(sqlType, save);
dispatcher.Notify(GetChangeType(sqlType), primaryKey, entityName, changes, GetChangeBy(save));

The webhook manager will queue up the notification and dispatch any webhooks subscribed to the event name, which is sewn together from the GetChangeType() "changed"/"created" and the entityName "person"

There is no event registry, so you can pass in what you like.

If you turn on logInformation you should be able to see the webhook system handling the events in the log file.

Alternatively you can go directly to SignalEvent, which takes the event name directly:

var dispatcher = SuperOffice.CRM.Webhooks.WebhookManager.GetCurrent();

dispatcher.SignalEvent("person.consented", primaryKey, "person", changes, SoContext.CurrentPrincipal.AssociateId);
Av: Christian Mogensen 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi,

Thanks Tony and Christian.

We have got softtrigger to work for tables that exists in the dictionary. 

However, the main objective was to be able to catch CDU events o tables created in Service(CS)-modue.
eg Extra Tables. and since they does not exist in the dictionary soft triggers cant be used?

See my 1-3 questions above.

I then guess that, in current SO version(S), it is not possible to define webhooks/soft trigers etc catching CDU operations on such Extra Table?

Or how could we solve this? 

Do you plan on nativley support webhooks for Extra Tables in the same way you do for contact, person , tickets etc in a near future?

Should we create a wish for this ? 

I think it would make scence to include support for Extra tables since this type of tables tends to be used more and more.

Best regards
/Anders

Av: Anders Larsson 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Custom tables (Extra tables) are a CS invention, so they don't go through NetServer.

NetServer knows about the tables, but modifications to these tables happens through Customer Service, which uses ODBC and SQL to modify the tables from C++ with no NetServer involvement.

 

Av: Christian Mogensen 5. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi,

Thanks Christian, 

So what you are saying is that per current so version. 8.5 R8, there is no way for us to track changes in the Extra Tables by any technology available in the SuperOffice stack?

As the Extra Tables can be read and updated by the built in rest-api since some time. Could that perhaps trigger something somewhere that could be catched by a webhook/create some event that could catched?

If not , could/will you build support for it in an upcoming release of SuperOffice?

 

Have a nice weekend

/Anders

 

Av: Anders Larsson 6. des 2019

RE: What are the configuration requirements to get at ISoftTriggerPlugin to work?

Hi Anders,

Yes, we are looking into how produce events/webhooks for service activities. We will announce it when we have something available in SOD to play with. 

Best regards.

 

Av: Tony Yates 9. des 2019