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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Creating custom boilerplate snippets

jensc
17-Peridot

Creating custom boilerplate snippets

Hello,

 

I want to preface this post with saying that I am not very good with Java, so please excuse any glaring rule breaking.

 

Anyway, I wanted to try and make some company specific boilerplate snippets.

I have managed to create a custom extension and I can import it into my platform correctly.

However when used, it returns a function like;

 

let ResultTypeName = doSomething();

 

Instead of what I am returning from the "doSomething" function.

 

I'm certain I am doing something wrong.

 

What I want is basically something similar to how the try/catch snippet works, or really almost any other snippet. 

 

I started with following this PTC article and also this document but felt it didn't really cover my needs.

So if anyone has any other resources around this, I'd very much appreciate it if they could post them here.

 

I'm also uploading my metadata and src file in case it is of interest.

 

Thanks,

Jens

ACCEPTED SOLUTION

Accepted Solutions
slangley
23-Emerald II
(To:jensc)

Hi @jensc.

 

We did more research on this and found that even if you're able to add snippets, only users in the Administrators group will be able to see them.

 

At this point in time, this is not a supported feature of ThingWorx and previous requests for this have not been approved.

 

Regards.

 

--Sharon

View solution in original post

8 REPLIES 8
slangley
23-Emerald II
(To:jensc)

Hi @jensc.

 

Since you're new to this, it would be recommended that you create a thing in Composer and add your services that way.  You can use export/import on the thing containing the code for transferring it to other environments.  This approach would allow you to become more familiar with the process prior to developing an extension.

 

Let us know if this works for getting it up and running.

 

Regards.

 

--Sharon

jensc
17-Peridot
(To:slangley)

Hello @slangley ,

 

I unfortunately don't think that that will do what I want.

 

Perhaps I have misunderstood the functionality of the "Script Function Library". I thought I would be able to create snippets similar to the out of the box ones. Ones like the Control flow snippets:

jensc_0-1683267175561.png

But perhaps it is just meant to create functions, which in hindsight makes sense I guess considering the name "Script 'Function' Library".

 

So I guess my first question is, am I way off?

 

Thanks,

Jens

slangley
23-Emerald II
(To:jensc)

Hi @jensc.

 

You won't be able to add to the built-in snippet library.  You can however create your own extension per the documentation you previously found.  These should provide the guidance needed for creating a custom extension containing your custom services which you can then reference via the thing.

 

Regards.

 

--Sharon

jensc
17-Peridot
(To:slangley)

Hello @slangley,

 

I was able to add a row in the snippets, but as it returned a function call instead of code, similar to some of the out of the box snippets, I don't think I can use it for my use case.

 

Is there no way of creating these Script Function Libraries in such a way that it can just write out regular JS code in the editor?

 

Regards,

Jens

slangley
23-Emerald II
(To:jensc)

Hi @jensc.

 

We're curious as to how you were able to add a row to the snippets.  Can you provide your steps for doing so?

 

There have been requests for this in the past but unfortunately it was rejected as a future enhancement to the product.

 

Regards.

 

--Sharon

jensc
17-Peridot
(To:slangley)

Hello @slangley,

 

I just followed the instructions for the Script Function Libraries in the documentation I mentioned in my first post.

From the PTC support article CS353554:

"Script Function Library can be used to extend Snippets with customized functions for custom services in ThingWorx Platform"

 

Here is my test snippet:

jensc_0-1684740508226.png

 

Which if used, provides the following code: 

jensc_1-1684740545646.png

 

Now, this is fine and all. But I also noticed that both the GitBackup extension and the Ghost resource also have their own snippets:

jensc_2-1684740604679.png

They produce this code:

jensc_3-1684740646213.png

 

Now, perhaps I have misunderstood the functionality of this and that this functionality only provides standard code, such as the params json and function calls.

 

So it might not be viable for my use case as a way to easily add boilerplate code for our citizen developers.

Attached you can find the extension if you want to test it out yourself.

 

Regards,

Jens

slangley
23-Emerald II
(To:jensc)

Hi @jensc.

 

We did more research on this and found that even if you're able to add snippets, only users in the Administrators group will be able to see them.

 

At this point in time, this is not a supported feature of ThingWorx and previous requests for this have not been approved.

 

Regards.

 

--Sharon

jensc
17-Peridot
(To:slangley)

Hello @slangley,

 

Alright, For now I guess we'll just have to do it the old fashioned way. Thank you for looking into it! 

 

Regards,

Jens

Announcements


Top Tags