1

Create unit with profile fields info by using javascript sdk

Тема: Create unit with profile fields info by using javascript sdk

Hello,
I want to create a unit with profile fields info using javascript sdk, in the documentation the method "createUnit" has 4 params only as following :
- creator
- unit name
- hardware id
- flag
- callback function

but i need to send profile fields also, how can i do that please?
thanks

2

Create unit with profile fields info by using javascript sdk

Re: Create unit with profile fields info by using javascript sdk

Hello. No, there is no such API to create object with additional properties in single request.

You need to create unit first and then update required props and fields.

3

Create unit with profile fields info by using javascript sdk

Re: Create unit with profile fields info by using javascript sdk

Hello rual,
Ok i understood you,
so kindly can you guide me to the method of update unit? is it

sess.updateItem()

or where can i search for that?
i have tried several ways
i have tested with returned obj
as :
obj.updateCustomProperty
i have received code=0 but the prop value doesn't saved in profile field of the unit
sad

thanks

4

Create unit with profile fields info by using javascript sdk

Re: Create unit with profile fields info by using javascript sdk

You need to do sess.loadLibrary("itemProfileFields") before loading items. Then fetch item (with wialon.item.Item.dataFlag.profileFields data flag) and it will have updateProfileField method.

A little more about loadLibrary and properties — https://forum.gurtam.com/viewtopic.php? … 13#p161813

5

Create unit with profile fields info by using javascript sdk

(23/12/2019 14:07:35 отредактировано Fadi Ramzi)

Re: Create unit with profile fields info by using javascript sdk

This is my simple code to create a unit with profile fields

sess.createUnit(sess.getCurrUser(), infoArr[0], this.state.selectedHWID, flags, function (code, obj) {
            console.log('reposne code is  : ')
            console.log(code)
            if (code === 0) {
                console.log(obj)
              
                obj.updateProfileField({itemId: obj._id ,n:"year",v:"2020"}, function(code,col){

                    console.log(' returned code' +code)
                    console.log(col)
                })
               
              
            }
            

        })

But i have got
{"error":4, "reason":"VALIDATE_PARAMS_ERROR: {itemId: long, n: text, v: text}"}

in network request console

i already have loaded "itemProfileFields"

i tried to do :

sess.getIIem(returnObj._id).updateProfileField..

but the item returned is null but i don't know why

so kindly can you explain me the correct procedure to reach updateProfileField method, is it by getITem or by returnObj.updateProfileField?

thanks

6

Create unit with profile fields info by using javascript sdk

Re: Create unit with profile fields info by using javascript sdk

You are very close.

Replace

obj.updateProfileField({itemId: obj._id ,n:"year",v:"2020"}, function(...

with:

obj.updateProfileField("year", "2020", function(...

sess.getItem() returns null because item is not loaded to a session with sess.updateDataFlags(...).

7

Create unit with profile fields info by using javascript sdk

Re: Create unit with profile fields info by using javascript sdk

Hahaha wow

I found out the problem and it's solution in the same time you was typing your sol for me
i was monitoring the form-data params sent  and found out that my input bad

thanks a lot my friend

regards,