Skip to main content
1-Visitor
May 12, 2020
Solved

EntityServices CreateThing Service does not apply Default Values

  • May 12, 2020
  • 1 reply
  • 2801 views

Hello everyone,

 

I've been trying to create 'Thing' in a batch mode, and I've decided to use the Resources["EntityServices"] CreateThing(). 

 

The service seems to work as intended. However, I can verify that the 'Thing' properties of my newly created Thing do not have the 'Default Values' I have configured. Has anyone had an issue with this in the past? 

 

Note: I'm using v8.4.1

Best answer by vinakumar

For your reference , this is the service code I am using

 

   var text    = '';
   var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    for ( var i = 0; i < 6; i++ ) {
      text += characters.charAt(Math.floor(Math.random() * i));
   }
try {
var params = {
 name: text /* STRING */,
 description: undefined /* STRING */,
 thingTemplateName: 'MyThingTemplate' /* THINGTEMPLATENAME */,
 tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateThing(params);
}
catch (err)
{
    logger.warn (err.message);
}
try {
     Things[text].EnableThing();
     Things[text].RestartThing();
}
catch (err)
{
    logger.warn (err.message);
}

 

Please define ThingTemplate with name "MyThingTemplate" with default property values before using above service code.

1 reply

12-Amethyst
May 13, 2020

Hi,

 

Are you creating Thing  from specific ThingTemplate which have some properties with default values ? If you are creating thing from Generic Thing template, then how you are setting default property values on thing . Please share that code.

rnfonseca1-VisitorAuthor
1-Visitor
May 13, 2020

Hello @vinakumar ,

 

I'm creating a thing from a specific ThingTemplate which has some properties with default values.

12-Amethyst
May 13, 2020

I am not seeing any issue at my end in seeing the default property values for Things created dynamically.