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