Features, discussions, tips, tricks, questions, problems and feedback

Server Script - Reading / Writing Agents

Hello All,

I’m working on a server script and I would like to know if there is a easy way to read agents to work with them inside a script, even in the spider or GF scripts, I think both can access agents in the same way, right?

I have one example here that works, However, I’m not sure that this is the best way to do it.

    // Perform a read on agents
    DataElement sol1 = DataElementEngine.NewDataElement("Adroit.Test.value");
    DataElementCollection dec = DataElementEngine.NewDataElementCollection();
    dec.Add(sol1);
    MethodReturnInfo info = MyConnection.ReadDataElements(dec);
    DataElementCollection collectionReturned = info.ReturnObject as DataElementCollection;

    foreach (DataElement de in collectionReturned.Values)
    {
        if (Convert.ToInt32(de.Value) > 280)
        {
            result = true;
        }
        else
        {
        }

Sometimes is only needed to check one agent and I made it using this whole code like the example.

Regards,

Hi Roldan,

This is the best and easiest way to read agent values from either server-side script, script spider script or graphic form script.

If you are just reading one agent value, then I would recommend just calling:

MethodReturnInfo ReadDataElement(string dataElementName);

Less code involved as below:

  MethodReturnInfo mri = MyConnection.ReadDataElement("Adroit.A1.value");

  DataElementCollection collectionReturned = mri.ReturnObject as DataElementCollection;         
  if (collectionReturned.Contains("Adroit.A1.value"))
  {
      DataElement de = collectionReturned["Adroit.A1.value"];
      if (Convert.ToInt32(de.Value) > 280)
      {
          MessageBox.Show("Value greater then 280");
      }
      else
      {
          MessageBox.Show("Value NOT greater then 280");
      }
  }

Regards,
Diego

1 Like

Thanks Diego,

I will test and let you know the results.

Regards,

Douglas

@DiegoA
I tried to read a Digital Agent inside a Server script, and it doesn’t work, If I copy the same script into a GF script or Spider Script it works fine.
Is there a way to debug a server script? I didn’t find that.

Regards,

Douglas

Hi Roldan,

For Server-side Scripts, a User Name and Password must be specified for scripts that interact with other data sources. In other words, those scripts that read and/or write data elements or call special functions etc. In your case, reading Adroit agent values via the Adroit data source

To specify a User Name and Password do the following:

Right-click the Scripts Data source and click Configure… as below:

image

In the Script Authentication dialog that opens, specify a User Name and Password, preferably a user that has read/write access to the data elements in the Adroit data source:

image

1 Like