447
Views
6
Comments
Solved
Javascript Not Working
Question

Hey Guys,

I have the following details in my web block:

SyntaxEditor Code Snippet

const configuration = {
  partnerID: '',
  userID: '',
};
var revieveSDK;
console.log("SDK Initialized");
function ReviceSetConf(input_userid, input_RevivepartnerID){
    console.log("Function");
    configuration.userID=input_userid;
    configuration.partnerID=input_RevivepartnerID;
    revieveSDK = new RevieveSDK(configuration.partnerID, true);
    revieveSDK.setUserId(configuration.userID);
    console.log(revieveSDK.getConfiguration());
}


I am calling the function using the below code in an expression in the same web block:

SyntaxEditor Code Snippet

"<script src='https://sdk.revieve.com/revieve-sdk.min.js'>
ReviceSetConf("+ReviveuserID+","+ RevivepartnerID+");
console.log(revieveSDK.getConfiguration());

</script>"

Where ReviveuserID and RevivepartnerID are the input parameters to the web block. The problem is that the above script does not seem to be getting executed (meaning the console prints only 'SDK Initialized'). Can anyone help?

2020-10-27 09-20-27
John Salamat
 
MVP
Solution

This worked on my end

Expression 1

"<script src='https://sdk.revieve.com/revieve-sdk.min.js'></script>"

Expression 2

"<script>
const configuration = {
  partnerID: '',
  userID: '',
};
var revieveSDK;
console.log('SDK Initialized');
function ReviceSetConf(input_userid, input_RevivepartnerID){
    console.log('Function');
    configuration.userID=input_userid;
    configuration.partnerID=input_RevivepartnerID;
    revieveSDK = new RevieveSDK(configuration.partnerID, true);
    revieveSDK.setUserId(configuration.userID);
    console.log(revieveSDK.getConfiguration());
}

ReviceSetConf('test','test');
console.log(revieveSDK.getConfiguration());
console.log('Started Function Exec');
</script>"

Note that changed I made on the parameters of ReviceSetConf

2020-03-05 14-29-02
José Costa

Hi Tanveer,

Having the src attribute and content in a script tag is a bad idea. Different browsers do different things and the recommendation is actually to not execute the content when the src exists (https://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#edef-SCRIPT).

So, I would define two script tags: one for the src file and the other for the content.

Tell me if that worked.

Cheers,

José

2018-10-03 09-30-08
Tanveer

José Costa wrote:

Hi Tanveer,

Having the src attribute and content in a script tag is a bad idea. Different browsers do different things and the recommendation is actually to not execute the content when the src exists (https://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#edef-SCRIPT).

So, I would define two script tags: one for the src file and the other for the content.

Tell me if that worked.

Cheers,

José

Thanks for the best practice, but that did not fix my problem of function not getting fired.

Within the Web Block I have two expressions now and it has the following code:

SyntaxEditor Code Snippet - Expression 1

"<script src='https://sdk.revieve.com/revieve-sdk.min.js'/>"

SyntaxEditor Code Snippet - Expression 2

"<script>
ReviceSetConf("+ReviveuserID+","+ RevivepartnerID+");
console.log(revieveSDK.getConfiguration());
console.log("+"Started Function Exec"+");
</script>"


Any other hints on how to get the second script to fire?

2020-10-27 09-20-27
John Salamat
 
MVP
Solution

This worked on my end

Expression 1

"<script src='https://sdk.revieve.com/revieve-sdk.min.js'></script>"

Expression 2

"<script>
const configuration = {
  partnerID: '',
  userID: '',
};
var revieveSDK;
console.log('SDK Initialized');
function ReviceSetConf(input_userid, input_RevivepartnerID){
    console.log('Function');
    configuration.userID=input_userid;
    configuration.partnerID=input_RevivepartnerID;
    revieveSDK = new RevieveSDK(configuration.partnerID, true);
    revieveSDK.setUserId(configuration.userID);
    console.log(revieveSDK.getConfiguration());
}

ReviceSetConf('test','test');
console.log(revieveSDK.getConfiguration());
console.log('Started Function Exec');
</script>"

Note that changed I made on the parameters of ReviceSetConf

2016-04-21 20-09-55
J.
 
MVP
ReviceSetConf("+ReviveuserID+","+ RevivepartnerID+");

Are you passing numbers or strings?

If you are passing strings, it's better to use this:

ReviceSetConf('"+ReviveuserID+"','"+ RevivepartnerID+"');
2020-03-05 14-29-02
José Costa

Hi Tanveer,

Are you getting any javascript errors in the DevTools of the browser?

Cheers,

José

2018-10-03 09-30-08
Tanveer

Thank you everyone. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.