cancel
Showing results for 
Search instead for 
Did you mean: 

How to use scriptArgs in executeWebScript?

d_moeyersons
Star Contributor
Star Contributor

Hey,

I don't understand how to use scriptArgs in [AlfrescoApiService].getInstance().webScript.executeWebScript in ADF.

I tried several ways, even using a regular string, but none of them worked.
I solved it for now by adding the args to tthe scriptPath and it works, but I wondered if someone could explain how the scriptArgs work.

this.apiService.getInstance().webScript.executeWebScript(
  'GET',
  `api/vmm/agendastructuur/workspace/SpacesStore/${result.id}?showAgendapunten=false`,
  null,
  null,
  null,
  null
).then(
  (response: any) => {
    const convertedResponse = this.objectToObjectArray(response);
    // console.log(convertedResponse);
    this.nodes = convertedResponse;
  }
);

Thanks!

David.

1 ACCEPTED ANSWER

Inside the project, there is an index.d.ts that should help your IDE to understand the types. Maybe your IDE is not configured in the riight way. Anyway, this the types:  :

executeWebScript(httpMethod?: string, scriptPath?: string, scriptArgs?: any, contextRoot?: string, servicePat?: string, postBody?: string): Promise<{}>;

It will compose an URL like that:

http(s)://(host):smileysad:port)/(contextPath)/(servicePath)/(scriptPath)?(scriptArgs)

scriptArgs is an object like that:

vat myParams = {
myUrlVar: 'value1',
myUrlVarTwo: 'value2',
};
‍‍‍‍‍‍‍‍‍

So for example, if you use it:

this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'mytasks', myParams, 'share', 'differentServiceSlug');

It should invoke 

http://127.0.01:8080/share/differentServiceSlug/mytasks?myUrlVar=value1&myUrlVarTwo=value2

View answer in original post

5 REPLIES 5

eugenio_romano
Elite Collaborator
Elite Collaborator

Hi Eugenio,

Thanks for answering.
The first thing that I have done was looking into the official documentation, I know where I should put the different parameters, but the exact format isn't defined there.
I already tried a flat string (in the example above it would be: "showAgendapunten=false") as third parameter, but I didn't get the desired results. I also tried an object, object Array, string Array as third parameter, it all didn't work.

David.

Inside the project, there is an index.d.ts that should help your IDE to understand the types. Maybe your IDE is not configured in the riight way. Anyway, this the types:  :

executeWebScript(httpMethod?: string, scriptPath?: string, scriptArgs?: any, contextRoot?: string, servicePat?: string, postBody?: string): Promise<{}>;

It will compose an URL like that:

http(s)://(host):smileysad:port)/(contextPath)/(servicePath)/(scriptPath)?(scriptArgs)

scriptArgs is an object like that:

vat myParams = {
myUrlVar: 'value1',
myUrlVarTwo: 'value2',
};
‍‍‍‍‍‍‍‍‍

So for example, if you use it:

this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'mytasks', myParams, 'share', 'differentServiceSlug');

It should invoke 

http://127.0.01:8080/share/differentServiceSlug/mytasks?myUrlVar=value1&myUrlVarTwo=value2

Thank you, this works.
My IDE (IntelliJ IDEA) is configured the right way to show hints, but I couldn't make out what the 'any' type stands for.

yep maybe we have to improve that type definition, good point thanks