- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2020 01:16 PM
Hi Team
I have a widget where I need to check if the logged in User belongs to a particular country, then the click on the widget should redirect to one page & if he belongs to another country, it should redirect to another page.There are 2 static pages & I am checking for 2 countries basically - US & UK. But however, I am not able to use the condition in my HTML template.
Server script :
(function() {
data.result = 'false';
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
if(gr.country == 'GB') - Country = UK
data.result= 'true';
} else { - Country = US
data.result= 'false';
}
})();
Client Script :
function() {
var c = this;
if($scope.data.result){
c.techbar = 'UK';
}else{
c.techbar = 'US';
}
}
HTML Template :
<div class="landing-button col-md-3 hidden-xs hidden-sm">
<a href="https://10to8.com/book/ustechbar/select-staff-and-location-if-needed/?service=1041505&prevent-change-service=true">
<img class="image" class="icon" src="icon_info2x.pngx">
<div class="heading">
<span class="name">Virtual TechBar</span>
<div class="bullet-div">
<span class="sub-title">Book appointment with Virtual TechBar</span>
</div>
</div>
<a href="https://10to8.com/book/ustechbar/select-staff-and-location-if-needed/?service=1041505&prevent-change-service=true"><span class="btn btn-landing answers">Virtual TechBar Appointment</span></a>
</a>
</div>
<div class="landing-button col-xs-12 visible-xs-block visible-sm-block">
<a href="/ksp?id=ksp_knowledge" class="btn btn-landing answers">
<img class="image" class="icon" src="icon_info_white2x.pngx"><br />
<span class="label">Virtual TechBar</span>
</a>
</div>
</div>
Can anyone please tell me how to check for conditions in the HTML code where the a href is going to change based on the Logged in User's country?
For US - I want the ref URL to be - a href = "https://10to8.com/book/ustechbar/select-staff-and-location-if-needed/?service=1041505&prevent-change-service=true"
For UK - I want the ref URL to be - a href ="https://10to8.com/book/techbar/"
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2020 02:28 PM
Hi Bidisha,
You don't need client controller here.
The server side will run first and based on the location of user the url will be set in the server side only.
We are using the same url in the html side using data.url which we are specifying in the server side.
Server script :
(function() {
data.result = 'false';
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
if(gr.country == 'GB') - Country = UK
data.url= 'https://10to8.com/book/ustechbar/select-staff-and-location-if-needed/?service=1041505&prevent-change-service=true'; //US
} else {
data.url= 'https://10to8.com/book/techbar/'; //UK location
}
})();
HTML side:
<div class="landing-button col-md-3 hidden-xs hidden-sm">
<a href="{{data.url}}" title="Open LINK">
<img class="image" class="icon" src="icon_info2x.pngx">
<div class="heading">
<span class="name">Virtual TechBar</span>
<div class="bullet-div">
<span class="sub-title">Book appointment with Virtual TechBar</span>
</div>
</div>
Client controller:
function() {
var c = this;
}
The Href is dynamic here and it will be fetching from the server side where you are checking the user country so do generate the url there only and use in the html side.
Only one html block is sufficient for the both the case as i mentioned above.
Mark helpful and correct if it helps.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2020 02:28 PM
Hi Bidisha,
You don't need client controller here.
The server side will run first and based on the location of user the url will be set in the server side only.
We are using the same url in the html side using data.url which we are specifying in the server side.
Server script :
(function() {
data.result = 'false';
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if (gr.next()) {
if(gr.country == 'GB') - Country = UK
data.url= 'https://10to8.com/book/ustechbar/select-staff-and-location-if-needed/?service=1041505&prevent-change-service=true'; //US
} else {
data.url= 'https://10to8.com/book/techbar/'; //UK location
}
})();
HTML side:
<div class="landing-button col-md-3 hidden-xs hidden-sm">
<a href="{{data.url}}" title="Open LINK">
<img class="image" class="icon" src="icon_info2x.pngx">
<div class="heading">
<span class="name">Virtual TechBar</span>
<div class="bullet-div">
<span class="sub-title">Book appointment with Virtual TechBar</span>
</div>
</div>
Client controller:
function() {
var c = this;
}
The Href is dynamic here and it will be fetching from the server side where you are checking the user country so do generate the url there only and use in the html side.
Only one html block is sufficient for the both the case as i mentioned above.
Mark helpful and correct if it helps.
Thanks,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2020 09:29 PM
Thanks a lot, it worked.