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