Add Script to Outsystems Mobile

Add Script to Outsystems Mobile

  

Hi.

I was wondering if it was possible to add a script like this --> <script type="text/javascript" data-app-id="YOUR-APP-CLIENT-ID" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>

to your mobile application.

Hi Saurav

You can do this.

Go to page and go to OnReady action and this Javascript block.

In that Javascript block, you can add your Javascript code.

Thanks and Regards,

Suraj Borade

Suraj Borade wrote:

Hi Saurav

You can do this.

Go to page and go to OnReady action and this Javascript block.

In that Javascript block, you can add your Javascript code.

Thanks and Regards,

Suraj Borade

Getting this error on Chrome: Uncaught SyntaxError: Unexpected token <


Check how you have typed your javascript code and google it out what that error means.

Also please go to debugger tool and check is there any details present.

Hello saurav,

No need to add <script> </script>

Outsystems already know you are adding js here.

Suraj Borade wrote:

Check how you have typed your javascript code and google it out what that error means.

Also please go to debugger tool and check is there any details present.

I googled the error. Most of them refer to upper case issues. I don't have those errors. And this was the error I got from debugging on Chrome. How else can I debug?


Hi Saurav,

Where you add JavaScript?

on page Javascript Property, Add javascript in preparation or else..



Hi, I found solution.

The problem is, You added <script></script> tag into your js.

I did the same for testing and get following output



But when I remove the <script></script> tag JS working good



Let me know your problem solved or not.

Gopal,

Great example but he is doing that for mobile application. So maybe from that Javascript block, he needs to remove <script> tag.

Yes Suraj, I tested on mobile also and the problems because of <script> tag

Yes since this is a javascript block, there is no need to mention script tag explicitly.

Saurav: Your problem should be solved just writing javascript code in the block.

Solution

Hi Saurav,

Suraj is right when he pointed you in the direction of using a JavaScript in the OnReady.
But you need to add it to the DOM. Here is a code that should work.

var script_src = 'https://c64.assets-yammer.com/assets/platform_js_sdk.js';
var head = document.getElementsByTagName('head')[0];
var new_script = document.createElement('script');
new_script.type = 'text/javascript';
new_script.src= script_src;
new_script.setAttribute('data-app-id', 'YOUR-APP-CLIENT-ID');
head.appendChild(new_script);

Remember that in yammer your domain must be whitelisted in the configuration:

https://developer.yammer.com/docs/js-sdk

Cheers,
Eduardo Jauch

Solution

Hi Eduardo,

Thanks for the further help.

You are a real Javascript master.

Thanks and Regards,

Suraj Borade

Eduardo Jauch wrote:

Hi Saurav,

Suraj is right when he pointed you in the direction of using a JavaScript in the OnReady.
But you need to add it to the DOM. Here is a code that should work.

var script_src = 'https://c64.assets-yammer.com/assets/platform_js_sdk.js';
var head = document.getElementsByTagName('head')[0];
var new_script = document.createElement('script');
new_script.type = 'text/javascript';
new_script.src= script_src;
new_script.setAttribute('data-app-id', 'YOUR-APP-CLIENT-ID');
head.appendChild(new_script);

Remember that in yammer your domain must be whitelisted in the configuration:

https://developer.yammer.com/docs/js-sdk

Cheers,
Eduardo Jauch

Thank you Eduardo. Worked fine, but I'm getting a new error: "XMLHttpRequest cannot load https://www.yammer.com/platform/login_status.json?client_id=wZuyoeLNhd1SR6pF5faXUg. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'https://saurav-sircar.outsystemscloud.com' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute."


I'm not sure how to add a header. Any idea how to fix this?


Saurav Sircar wrote:

Eduardo Jauch wrote:

Hi Saurav,

Suraj is right when he pointed you in the direction of using a JavaScript in the OnReady.
But you need to add it to the DOM. Here is a code that should work.

var script_src = 'https://c64.assets-yammer.com/assets/platform_js_sdk.js';
var head = document.getElementsByTagName('head')[0];
var new_script = document.createElement('script');
new_script.type = 'text/javascript';
new_script.src= script_src;
new_script.setAttribute('data-app-id', 'YOUR-APP-CLIENT-ID');
head.appendChild(new_script);

Remember that in yammer your domain must be whitelisted in the configuration:

https://developer.yammer.com/docs/js-sdk

Cheers,
Eduardo Jauch

Thank you Eduardo. Worked fine, but I'm getting a new error: "XMLHttpRequest cannot load https://www.yammer.com/platform/login_status.json?client_id=wZuyoeLNhd1SR6pF5faXUg. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'https://saurav-sircar.outsystemscloud.com' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute."


I'm not sure how to add a header. Any idea how to fix this?


Hello Saurav,

Have you included your site in the list of the site?

Your application must be set in there, so the Yammer accepts the XMLHttpRequest.
This is always done in the side that will receive the request, not in your application

Cheers,
Eduardo Jauch


Eduardo Jauch wrote:

Saurav Sircar wrote:

Eduardo Jauch wrote:

Hi Saurav,

Suraj is right when he pointed you in the direction of using a JavaScript in the OnReady.
But you need to add it to the DOM. Here is a code that should work.

var script_src = 'https://c64.assets-yammer.com/assets/platform_js_sdk.js';
var head = document.getElementsByTagName('head')[0];
var new_script = document.createElement('script');
new_script.type = 'text/javascript';
new_script.src= script_src;
new_script.setAttribute('data-app-id', 'YOUR-APP-CLIENT-ID');
head.appendChild(new_script);

Remember that in yammer your domain must be whitelisted in the configuration:

https://developer.yammer.com/docs/js-sdk

Cheers,
Eduardo Jauch

Thank you Eduardo. Worked fine, but I'm getting a new error: "XMLHttpRequest cannot load https://www.yammer.com/platform/login_status.json?client_id=wZuyoeLNhd1SR6pF5faXUg. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'https://saurav-sircar.outsystemscloud.com' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute."


I'm not sure how to add a header. Any idea how to fix this?


Hello Saurav,

Have you included your site in the list of the site?

Your application must be set in there, so the Yammer accepts the XMLHttpRequest.
This is always done in the side that will receive the request, not in your application

Cheers,
Eduardo Jauch


Hi Eduardo.

Yes, I have included then under the Javascript Origins section.


Hello Saurav,

Have you found a solution to this error?
I think that maybe you will have to do a "preauthorization": https://blogs.technet.microsoft.com/askyammer/2016/11/04/preauthorizing-the-yammer-js-sdk/

But I'm not sure.

Cheers,
Eduardo Jauch