1. Module JDisc

    Article: AN0002475Updated: 17.05.2022

    This module enables to read data from the discovery system JDisc.

    JDisc discovery software

    We can use below stated script e.g. in a button on ObjectGears web or in a script executed by ObjectGears winservice. We define in the script what we want to read from JDisc and where to store these data. Function merge provides storing new data, update of existing data and deletion of data that are not in JDisc any more.

    var jd = OG.Module['og_jdisc'].CreateJDisc('https://localhost/graphql');
    var j = 'jdisc_account';
    var h = 'password_to_jdisc';
    jd.Login(j, h);

    var query = '{"query":"{ devices{ findAll{ name id} } }","variables":null}';
    var devices = jd.GetData(query, 'data.devices.findAll');

    //logout from JDisc
    jd.LogOut();

    if (devices != null)
    {
    var cl = OGModel.ClassDefs['devices'];
    var colId = cl.Columns['order']; //record id
    var colName = cl.Columns['name']; //name
    var colDate = cl.Columns['datetime']; //date of update
    //delete indication of update
    var sql = OG.TextUtils.Format('update {0} set {1} = null', cl.DBTableName, colDate.DBColumnName);
    OG.Sql.RunSql(sql);

    //data merge
    sql = OG.TextUtils.Format(
    'MERGE {0} AS target ' +
    'USING (SELECT @id, @name) AS source (id, name) ' +
    'ON target.{2} = source.id ' +
    'WHEN MATCHED THEN ' +
    ' UPDATE SET target.{3} = source.name, {1} = getdate() ' +
    'WHEN NOT MATCHED THEN ' +
    ' INSERT({2}, {3}, {1}, created, creator, CreatedDataSourceId) VALUES(source.id, source.name, getdate(), getdate(), @user, 8);',
    cl.DBTableName, colDate.DBColumnName, colId.DBColumnName, colName.DBColumnName);

    var d2 = devices.ToList();
    for( var i = 0; i < d2.Count; ++i)
    {
    var d = d2[i];

    var pars = OG.Sql.CreateParameterList();
    pars.AddInt('id', d['id']);
    pars.AddNvarchar('name', d['name']);
    pars.AddNvarchar('user', OG.Person.GetLoginPerson().Account);

    OG.Sql.RunSql(null, sql, pars);
    }
    }
    else
    {
    OGForm.SetInfo('Data not found.');
    }

     

×