cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to create style definition through services in thingworx ?

Sugumar_5656
14-Alexandrite

How to create style definition through services in thingworx ?

I need to get the input from the front end mashup then i like to create the style definition based on the input using services, further i like to update the particular widgets style definition with that newly created style.

 

thanks in advance...

1 ACCEPTED SOLUTION

Accepted Solutions

Combining both and after some tests, this is the correct format :

 

var name = "NewTestStyle3";
try{
    Resources["EntityServices"].CreateStyleDefinition({
        name: name,
        description: undefined ,
        content: { "content" : 
                  {   "params": "",
                       "image":"",
                       "backgroundColor":"#d49d13",
                       "textSize":"normal",
                       "lineStyle":"dotted",
                       "displayString":"Series 15",
                       "fontEmphasisUnderline":false,
                       "fontEmphasisItalic":false,
                       "lineThickness":1,
                       "lineColor":"#ffac20",
                       "foregroundColor":"#ffdc84",
                       "fontEmphasisBold":false,
                       "secondaryBackgroundColor":"#ffb22f"
                  
                  }
                 },
        tags: undefined 
    });


}catch(err) {
    logger.error("EERROR STYLE CREATION "+err);
    Resources["EntityServices"].DeleteStyleDefinition({
        name: name
    });
}

View solution in original post

4 REPLIES 4
vxavier
13-Aquamarine
(To:Sugumar_5656)

There is a snippet:

 

var params = {
	name: undefined /* STRING */,
	description: undefined /* STRING */,
	content: undefined /* JSON */,
	tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateStyleDefinition(params);

But I don't know how to use it properly.  I am curious about how to do this too.  

Sugumar_5656
14-Alexandrite
(To:vxavier)

thank you for your reply xavior,

i know there is a separate snippet available in the service part. but i also dont know how to use that one.

 

In that snippet where do we need to give input for color code and text format? 

If you look at my answer on how to get Style Information: https://community.ptc.com/t5/ThingWorx-Developers/Get-style-information-of-style-definition/m-p/548275

 

you can see that the context format for style may look something like:

 

{  
   "image":"",
   "backgroundColor":"#d49d13",
   "textSize":"normal",
   "lineStyle":"dotted",
   "displayString":"Series 15",
   "fontEmphasisUnderline":false,
   "fontEmphasisItalic":false,
   "lineThickness":1,
   "lineColor":"#ffac20",
   "foregroundColor":"#ffdc84",
   "fontEmphasisBold":false,
   "secondaryBackgroundColor":"#ffb22f"
}

Combining both and after some tests, this is the correct format :

 

var name = "NewTestStyle3";
try{
    Resources["EntityServices"].CreateStyleDefinition({
        name: name,
        description: undefined ,
        content: { "content" : 
                  {   "params": "",
                       "image":"",
                       "backgroundColor":"#d49d13",
                       "textSize":"normal",
                       "lineStyle":"dotted",
                       "displayString":"Series 15",
                       "fontEmphasisUnderline":false,
                       "fontEmphasisItalic":false,
                       "lineThickness":1,
                       "lineColor":"#ffac20",
                       "foregroundColor":"#ffdc84",
                       "fontEmphasisBold":false,
                       "secondaryBackgroundColor":"#ffb22f"
                  
                  }
                 },
        tags: undefined 
    });


}catch(err) {
    logger.error("EERROR STYLE CREATION "+err);
    Resources["EntityServices"].DeleteStyleDefinition({
        name: name
    });
}

Top Tags