Question

populate lookup from script task

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