Hi everyone,

I need to call a sub-process from a C# script task, I found this code:

var showAdressProcessUId = new Guid("abfbf7ee-e499-45e9-9d22-b9e91a46683d");
var manager = UserConnection.ProcessSchemaManager;
var schema =  (ProcessSchema)manager.GetInstanceByUId(showAdressProcessUId);
var moduleProcess = schema.CreateProcess(UserConnection);
moduleProcess.SetPropertyValue("PageInstanceId", PageInstanceId);
moduleProcess.SetPropertyValue("ActiveTreeGridCurrentRowId", ActiveTreeGridCurrentRowId);
moduleProcess.SetPropertyValue("TreeGridSelectedRowsIds", TreeGridSelectedRowsIds);
moduleProcess.SetPropertyValue("SchemaName", "Contact");
moduleProcess.SetPropertyValue("RouteMode", false);
moduleProcess.Execute(UserConnection);

From ShowContactAddressOnMapProcess

If I use it for my process:

var _sendMailId = new Guid("84e96844-b0ae-4edc-8b5e-20d1ba13fb8b");
var _manager = UserConnection.ProcessSchemaManager;
var _schema = (ProcessSchema)_manager.GetInstanceByUId(_sendMailId);
var _moduleProcess = _schema.CreateProcess(UserConnection);
_moduleProcess.SetPropertyValue("Test1", "Something");
_moduleProcess.Execute(UserConnection);

Throws this exception :

Terrasoft.Common.InvalidObjectStateException: missing property "Test1" of type "ProcessComponentSet".

 

I would need to know how it works or another way to do it, I need to call a sub-process inside a for loop.



Thanks.

Like 0

Like

6 comments

Dear Ezequiel,

It is nor recommended to use sub-processes and the processes in general for such purpose. Technically you can call a business process from a business process. But if you correct the code above and execute it  the system will freeze and the processes will block each other. All users meanwhile will not be able to use the system properly.

Please adjust the business-purpose you want to achieve in order to avoid using business-processes or find another architecture solution.

Oliver

Hi, 

I see, I'm trying to send an email inside the loop, but I can't find in any of the existing process how to send an email with a template though a script task.

If someone knows how to do it or has an example, I would appreciate it if you could explain it or show it to me.

Thanks.

Dear Ezequiel,

There is "Send email" BP element you can use to reach your goal. Just select in a message input "Template message" and you will be able to choose what template to use.

 

 

Peter Vdovukhin,

Yes I know, but like I said I need to use it in a for loop, with that I could use it if I had the code to call a sub-process from a script task.

Dear Ezequiel,

As you wrote to bpm'online support, let's continue our conversation there. After resolving your task I will post an answer here.

Here is a simple example I have successfully tested:

A first business process contains only script task with such code:

for(int i = 0; i < 2; i++) {

    var _sendMailId = new Guid("cc1b3e27-4d11-4957-ac40-b22ff5b11aff");

    var _manager = UserConnection.ProcessSchemaManager;

    var _schema = (ProcessSchema)_manager.GetInstanceByUId(_sendMailId);

    var _moduleProcess = _schema.CreateProcess(UserConnection);

    _moduleProcess.SetPropertyValue("UsrTestParameter", "Letter number " + i);

    _moduleProcess.Execute(UserConnection);

}

A second business process with GUID = cc1b3e27-4d11-4957-ac40-b22ff5b11aff contains only Send email element that has a text parameter UsrTestParameter and use this parameter for email subject. The second business process HAS to be compiled to be called from the first business process.

Show all comments

Hi there! 

I'm looking an example and a step by step to call an own DLL from an element of BPM, probably "Task Script".

I tried to use something similar to what is proposed in the article: https://community.bpmonline.com/questions/integration-bpmonline-other-a…

but it did not work

Regards.

 

Like 0

Like

1 comments



Hello community!

I need get in a bussines process a collection parameter and then use that in a script task into a foreach. Any example about that?

 

Regards,

 

Like 0

Like

5 comments

Dear Federico,

Please check the instructions on how to work with collections within [Read data element]. This will help you to implement your own process.



Algorithm of the work with a collection from Read data:



1.Disable the formula validator in business process designer. You can open the console and execute the following script for that:

var featureCode = "UseProcessFormulaServerValidation";

require(["FeatureServiceRequest"], function() {

                var featureRequest = Ext.create("Terrasoft.FeatureServiceRequest", {code: featureCode});

                featureRequest.updateFeatureState({

                               forAllUsers: true,

                               state: Terrasoft.FeatureState.DISABLED // ENABLED

                }, ()=>console.log("Done"));

});

 

2. In [Read data] element go to extended options and tick:

Read first = true

Number of records to read = 100 //Number of records available in a collection.



3. Create a process parameter with EntityCollection type and map it to the resulting collection of [Read data]. This parameter does not exist out of the box, but you can create it manually. 

Example:

[#MyRead.Resulting collection#]

*  MyRead – [Read data] element header.

* Resulting Collection - added manually

 

4. Assign a process parameter to a new variable in ScriptTask. Here is the example how to process the collection:

EntityCollection entities = Get("MyEntity");

var result = new Collection();

foreach(Entity entity in entities) {

                var cityName = entity.GetTypedColumnValue("Id");

                string temp = cityName.ToString();

                result.Add(temp);

                }

 

string displayValue = result.ConcatIfNotEmpty(",");

Set("MyResult", displayValue);

return true;

 

MyRead – reading datat in any element.

MyEntity process parameter with EntityCollection type. Parameter value= [#MyRead.Resulting collection#]

MyResult - string parameter. You can store record IDs from the collection. Then this parameter is shown on the auto generated page for the testing purposes.  

Best regards,

Lily

Lily Johnson,

Hello,

I tried the above script task as below:

EntityCollection entities = Get("MyEntity");

var result = new Collection();

foreach(Entity entity in entities) {

                var productName = entity.GetTypedColumnValue("Name");

                string temp = productName.ToString();

                result.Add(temp);

                }

string displayValue = result.ConcatIfNotEmpty(",");

Set("UsrLatestOrderProduct", displayValue);

return true;

 

But, here I'm getting below errors:

 

Lily Johnson,

Hello,

 

Can you elaborate on how Auto-Generated Page works upon this case? 

 

Many Thanks

Riddhi Jadeja,



As we can see from the screenshots you have provided - GetTypedColumnValue is used incorrectly. 

GetTypedColumnValue("Name") is used without specified type of this field. 

It should be GetTypedColumnValue<string>("Name")



Kind regards,

Roman

Sarthak Jain,



Can you please specify your question with more details? 

How exactly Auto-Generated Page will be related to the discussed case? 



Thank you in advance,

Roman

Show all comments

Hello Community!

Any have a example to send a notification menssage from script task c#?

The idea is make a foreach and for each value send a notification to the user.

Regrads, 

 

Like 1

Like

2 comments

Dear Federico,

Here's the example for you:

//create reminding
/**
                 * @param addresserContactId // select Id from Contact
                 * @param addresseeContactId //select Id from Contact
                 * @ RemindTime {DateTime}
                 * @param description {String}
                 * @param subjectRecordId //select Id from [your schema]
                 * @param sourceId // select Id from RemindingSource --where Name = 'Owner' or Name = 'Author'
                 * @param sysSchemaUid //select Uid from SysSchema where Name = [your schema]
                 * @param subjectCaption {String}
                 * @param typeCaption {String}
                 *
                 * return {Terrasoft.Collection of InsertQuery}
                 */
                createRemindingInsert: function (addresserContactId, addresseeContactId, remindTime, description,
                                                 subjectRecordId, sourceId, sysSchemaUid, subjectCaption, typeCaption) {
                    var insert = Ext.create('Terrasoft.InsertQuery', {
                        rootSchemaName: "Reminding"
                    });
                    insert.setParameterValue('Id', Terrasoft.generateGUID(), Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('CreatedOn', new Date(), Terrasoft.DataValueType.DATE_TIME);
                    insert.setParameterValue('CreatedBy', Terrasoft.SysValue.CURRENT_USER_CONTACT.value, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('ModifiedOn', new Date(), Terrasoft.DataValueType.DATE_TIME);
                    insert.setParameterValue('ModifiedBy', Terrasoft.SysValue.CURRENT_USER_CONTACT.value, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('Author', addresserContactId, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('Contact', addresseeContactId, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('RemindTime', remindTime, Terrasoft.DataValueType.DATE_TIME);
                    insert.setParameterValue('Description', description, Terrasoft.DataValueType.TEXT);
                    insert.setParameterValue('SubjectId', subjectRecordId, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('Source', sourceId, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('SysEntitySchema', sysSchemaUid, Terrasoft.DataValueType.GUID);
                    insert.setParameterValue('SubjectCaption', subjectCaption, Terrasoft.DataValueType.TEXT);
                    insert.setParameterValue('TypeCaption', typeCaption, Terrasoft.DataValueType.TEXT);
 
                    return insert;
                },
                /**
                 *
                 * @param remindingInsertCollection {Terrasoft.Collection of InsertQuery}
                 * @param callback
                 */
                executeReminding: function (remindingInsertCollection, callback, scope) {
                    var batchQuery = Ext.create("Terrasoft.BatchQuery");
                    Terrasoft.each(remindingInsertCollection.getItems(), function (insertQuery) {
                        batchQuery.add(insertQuery);
                    });
                    batchQuery.execute(callback, scope);
                }

Lisa

Lisa Brown,

Hi Lisa. Its been a few yrs since your reply. Is there a better way to do this in the product now? The code you have mentioned writes to the DB and triggers an execute. 

Show all comments

Hello everyone!

I hope you can help me!

I want get the value of a property of a element of my Business Process.In this case, I read all of a employee and from my script task, I want to ask about the value of one of fields, "UsrClaveAltaTemprana". The compilation of the script task is correct but when I do the test from the employee's page and I will see ths process log it pulls the following error.

System.NullReferenceException: Object reference not set to an instance of an object.

   at Terrasoft.Common.ReflectionUtilities.GetPropertyValueByPath(Object source, String propertyPath)

   at Terrasoft.Core.Process.ProcessModel.Get[T](String propertyPath)

   at Terrasoft.Core.Process.UsrProcess3MethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context)

   at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

I attached image

 

 

 

 

 

 

 

       

I appreciated your help!

King Regards,

 

Ezequiel Gómez

Like 0

Like

1 comments

Dear Ezequirel,

The reason for an error is that you are trying to obtain value of an Id. Let me explain. 

"UsrClaveAltaTemprana" is a lookup field. Basically, it is a link to another object, so in database it is stored as an Id, but not the value.

If you intend to receive a value, you need to insert a "Read Data" element before a script task. Read the value from the object of "UsrClaveAltaTemprana" lookup, where Id equals the Id retrieved from the record. 

Set received value to new parameter. Then use this parameter in script task.

Hope this helps.

Regards, 

Anastasia

Show all comments

Hello Community!

I need populate a lookup from the script task. The script connect to webservice returning a json result.

So i need with the object data:[ { id: and title } ]  insert a new value in a lookup.

Is that posible insert more that one object from script task?

Regards, 

  "per_page": 50,
    "total": 2,
    "data": [
        {
            "href": "www.asd.asda",
            "nickname": "",
            "id": "123882212",
            "title": "Comentarios de clientes de software y aplicaciones con NPS®"
        },
        {
            "href": "www.test2.com",
            "nickname": "",
            "id": "123883983",
            "title": "Titulo Nuevo"
        }
    ],
    "page": 1,
    "links": {
        "self": "www.ooo.ooo"
    }

 

Like 0

Like

7 comments

Hi Federico,

Inside the script you can create an entire program if you need. You can read that json, deserialize it and create a loop to insert all records you need inside BPMOnline.

This logic is using standard C# code.

Thanks Rommel,

You have a example of creating entire program from the script?

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #e4af0a}
span.s1 {color: #454545}
span.s2 {color: #e4af0a}
span.Apple-tab-span {white-space:pre}

This a generic code you could use to call your service and get response. You will need to include the library Newtonsoft.Json in the process.

 

try {

 

    // preparing web service call

    string message = “{my json message}”;

    string url = "https://api.myapp.com”;

    HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);

    httprequest.Method = "POST";

    httprequest.ContentLength = message.Length;

    httprequest.ContentType = @"application/json";

 

    // calling service

    using(Stream streamresponse = httprequest.GetRequestStream())

        {

            streamresponse.Write(message, 0, message.Length);

        }

    

    // getting response

    using (HttpWebResponse response = (HttpWebResponse)httprequest.GetResponse()) {

        using (var streamReader = new System.IO.StreamReader(response.GetResponseStream()))

    {

        string result = streamReader.ReadToEnd();

        dynamic dynObj = JsonConvert.DeserializeObject(result);        

 

        ==>  dynObj will have the Json returned converted in an object

    }

}

And for insert the object in bpm? with the add data or is posbible by c# code?

 

You can do it directly in c# and it will be faster. Please refer to academy:  https://academy.bpmonline.com/documents/technic-sdk/7-11/crud-operation…

There are examples of how to do that. It's very simple.

I try that with the code : 

var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];

var insert = new Insert(userConnection).Into("Contact")
        .Set("Name", Column.Parameter("Federico"))
        .Set("Address", Column.Parameter("MyHouse")); 

    

return true;

But is not adding nothing. Is necesary something else?

Regars, 

 

add this line:

insert.Execute

Show all comments

Hello community!

I need show a menssage fron the script task on a business process. Or a console log in the browser can be found.

Can you have a example of that?

Regards, 

Like 0

Like

1 comments
Best reply

Hi Federico,

Your requirement have a couple of issues: 1) a business process can be executed in background, that means that no user could be logged when process runs and 2) for previous point, business process runs on the server side. If it tries to show a dialog or write on console, that will happen on the server.

Saying that, I have a couple of suggestions:

a) In your script you can save the information you want to show to users in a variable. Then after Script, you can Open an Auto generated Form, displaying the text you just generated. This works with a process that interacts with an user.

b) You can create a new Object and then, inside the script insert your results on this table to review them later.

Hi Federico,

Your requirement have a couple of issues: 1) a business process can be executed in background, that means that no user could be logged when process runs and 2) for previous point, business process runs on the server side. If it tries to show a dialog or write on console, that will happen on the server.

Saying that, I have a couple of suggestions:

a) In your script you can save the information you want to show to users in a variable. Then after Script, you can Open an Auto generated Form, displaying the text you just generated. This works with a process that interacts with an user.

b) You can create a new Object and then, inside the script insert your results on this table to review them later.

Show all comments