Inventory service in Web sdk

Product/components used and version/fix level:

c8y_version: 1018.0.240

Detailed explanation of the problem:

I am developing an Angular application using Web sdk in which I want to update an managed object i.e I want to update the fragment value of managed object like “c8y_Value”: true or false based on some condition
my fragment:

"c8y_Value": "false",
clicked(event,context){
    if(event.target.checked){
      console.log("toggle switch clicked")
      console.log(context);
      // api call to be made here
        const partialUpdateObject: Partial<IManagedObject> = {
        customFragment: 'Changed data',
        name: 'Name'
        };
        
        (async () => {
        const {data, res} = await this.inventory.update(partialUpdateObject);
        })();
      
    }else{
      console.log("toggle switch unclicked");
      console.log(context)
    }
  }

attached the code snippet for the same, what should be there in the custom fragment?

Hi @rushikesh_n,

You would need to provide the id of the managedObject you would like to update to the update method as well. In below sample I’m assuming that your context is having the id of the managedObject you would like to update and that the event is an Input Event coming from an checkbox input. The c8y_Value attribute will be updated to true in case that the checkbox is checked and to false in case it is unchecked.

  async clicked(event: InputEvent, context) {
    const eventTarget = event.target as HTMLInputElement;
    const partialUpdateObject: Partial<IManagedObject> = {
      c8y_Value: !!eventTarget.checked,
      id: context.id
    };

    const { data, res } = await this.inventory.update(partialUpdateObject);
  }

Regards,
Tristan

1 Like

Thanks @Tristan_Bastian for helping

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.