SBX - Search With Button

SBX - Forum Post Title

JS is not working in localized content of web page dynamics portal

Microsoft Dynamics CRM Forum

Microsoft Dynamics 365 Consultancy asked a question on 21 May 2019 5:16 AM
My Badges

Question Status

Suggested Answer

Hello Everyone!

Hope all of you are well! I created a web page in dynamics portal and added my custom JS code in localized content of web page but when my page loads so JS code does not execute. I also added " window.addEventListener('load', updateViewIdea); " method in my code but this method does not execute when page load. 

Can anyone tell me how to resolve this issue? I have also JS code in another localized content of web page with approximatly same code and that is running well . I do not know why this code is not running successfully.

Reply
Oliver Rodrigues responded on 24 May 2019 3:44 AM
My Badges
Suggested Answer

can you share the code?

can you try something as simple as:

$(document).ready(function () {

   alert("hello world");

});

Reply
Microsoft Dynamics 365 Consultancy responded on 29 May 2019 2:44 AM
My Badges

debugger;

function updateViewIdea() {
try {
alert("hello");
debugger;
console.log("distinguish log by shahroz");
// Update status bar
updateStatusBar(); // BPF Function

showClosedReasonText();

ChangeNoteButtonClass();

// Hide status elements
$("#unsw_ideastatus").hide();
$("#unsw_ideastatus_label").hide();
$("#unsw_ideadirection").hide();
$("#unsw_ideadirection_label").hide();
$("#unsw_backlog").hide();
$("#unsw_backlog_label").hide();
$("#unsw_isrequirements").hide();
$("#unsw_isrequirements_label").hide();
$("#unsw_viability").hide();
$("#unsw_viability_label").hide();
$("#unsw_concept").hide();
$("#unsw_concept_label").hide();

$("#unsw_bpfstagebeforeclose").hide();
$("#unsw_bpfstagebeforeclose_label").hide();


// Hide Update button
$('#UpdateButton').hide();

// Create simple bullet list from 'Who might benefit from this' answers
var y = $('legend:contains("Who might benefit")');
$(benefitList).insertAfter(y);

appendChosenBenefit("unsw_students", "unsw_students_label");
appendChosenBenefit("unsw_academicstaff", "unsw_academicstaff_label");
appendChosenBenefit("unsw_professionalstaff", "unsw_professionalstaff_label");
appendChosenBenefit("unsw_community", "unsw_community_label");
appendChosenBenefit("unsw_other", "unsw_other_label");
}
catch (ex) {
alert("Error in updateViewIdea method: " + ex.message);
}
}

/**
* Show a label text under the status bar with idea close reason
* @return {Null}
*/
function showClosedReasonText() {
try {
// Hide text area that shows comments on the form
$("#unsw_ideaclosecomments").hide();

//What is the reason text from the close comments text area?
var reason = $("#unsw_ideaclosecomments").text();

// If there is a value for close comments, add it to label at top of page
if (reason.length > 0) {
var reasonLabel = $("#ideaClosureReason");
reasonLabel.html("Reason for Idea Closure: " + reason);
}

// Hide text area that shows comments on the form
$("#unsw_ideaclosecomments").text = '.';
$("#unsw_ideaclosecomments_label").hide();
}
catch (ex) {
alert("Error in showClosedReasonText method: " + ex.message);
}
}

/**
* Update status bar
* @return {Null}
*/
function updateStatusBar() {
try {
// Hide completed stage
// $("#status-Completed").hide();

// Hide closed stage
// $("#status-Closed").hide();

// Hide closed stage
// $("#status-ExternalDocumentAnalysis").hide();

// Hide on-hold stage
// $("#status-On-Hold").hide();
// $("#status-On-Hold").attr('class', 'progress-done progress-current');

var statusSelectControl = document.getElementById("unsw_ideastatus");
var statusIndex = statusSelectControl.selectedIndex;
// alert("Status Index : " + statusIndex);
var directionSelectControl = document.getElementById("unsw_ideadirection");
var directionIndex = directionSelectControl.selectedIndex;

var isBacklog = false;
if (document.getElementById("unsw_backlog_1").checked) {
isBacklog = true;
}

var isRequirements = false;
if (document.getElementById("unsw_isrequirements_1").checked) {
isRequirements = true;
}

var isViability = false;
if (document.getElementById("unsw_viability_1").checked) {
isViability = true;
}

var isConcept = false;
if (document.getElementById("unsw_concept_1").checked) {
isConcept = true;
}

//alert("IsBacklog: " + isBacklog);
//alert("isRequirements: " + isRequirements);
//alert("isViability: " + isViability);
//alert("isConcept: " + isConcept);


switch (statusIndex) {
case 1:
//lodgement
$("#status-Initiate").attr('class', 'progress-done progress-current');
$("#status-Review").hide();
$("#status-Finance").hide();
$("#status-Validate").hide();
$("#status-Finalize").hide();
break;
case 2:
//External Document Analysys
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done progress-current');
$("#status-Finance").hide();
$("#status-Validate").hide();
$("#status-Finalize").hide();

break;
case 3:
// In consultation status
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").attr('class', 'progress-done progress-current');
$("#status-Validate").hide();
$("#status-Finalize").hide();

break;
case 4:
// In assessment status

$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance".attr('class', 'progress-done');
$("#status-Validate").attr('class', 'progress-done progress-current');
$("#status-Finalize").hide();

break;
case 5:
// Prioritisation

$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").attr('class', 'progress-done');
$("#status-Validate").attr('class', 'progress-done');
$("#status-Finalize").attr('class', 'progress-done progress-current');
break;
}
}
catch (ex) {
alert("Error in updateStatusBar method: " + ex.message);
}
}

function updateStatusBarAsClosedOrCompleted() {
try {

var isBacklog = false;
if (document.getElementById("unsw_backlog_1").checked) {
isBacklog = true;
}

var isRequirements = false;
if (document.getElementById("unsw_isrequirements_1").checked) {
isRequirements = true;
}

var isViability = false;
if (document.getElementById("unsw_viability_1").checked) {
isViability = true;
}

var isConcept = false;
if (document.getElementById("unsw_concept_1").checked) {
isConcept = true;
}

var lastStatus = $("#unsw_bpfstagebeforeclose").val();

if (lastStatus == "Initiate") {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").hide();
$("#status-Finance").hide();
$("#status-Validate").hide();
$("#status-Finalize").hide();
}
if (lastStatus == "Review") {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").hide();
$("#status-Validate").hide();
$("#status-Finalize").hide();
}

else if (lastStatus == "Finance") {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").attr('class', 'progress-done');
$("#status-Validate").hide();
$("#status-Finalize").hide();
}
else if (lastStatus == "Validate") {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").attr('class', 'progress-done');
$("#status-Validate").attr('class', 'progress-done');
$("#status-Finalize").hide();
}
else if (lastStatus == "Finalize") {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").attr('class', 'progress-done');
$("#status-Finance").attr('class', 'progress-done');
$("#status-Validate").attr('class', 'progress-done');
$("#status-Finalize").attr('class', 'progress-done');
}
else {
$("#status-Initiate").attr('class', 'progress-done');
$("#status-Review").hide();
$("#status-Finance").hide();
$("#status-Validate").hide();
$("#status-Finalize").hide();
}
}
catch (ex) {
alert("Error in updateStatusBarAsClosedOrCompleted method: " + ex.message);
}
}

/**
* Finds a value from a radio button and adds it to a new list
* @param {Element} benefitItemSelect - Select control
* @param {Element} benefitItemLabel - Label control
* @return {Null}
*/
function appendChosenBenefit(benefitItemSelect, benefitItemLabel) {
try {
// What is the selected index?
var isSelected = document.getElementById(benefitItemSelect).selectedIndex;

// If selected index is '1', then it is 'yes'. Else do nothing.
if (isSelected == 1) {
// Get the text value of the label
var textValue = document.getElementById(benefitItemLabel).textContent;

// Create a HTML list item
var entry = document.createElement('li');
entry.appendChild(document.createTextNode(textValue));

// Add list item to list
var list = document.getElementById("benefitList");
list.appendChild(entry);
}
}
catch (ex) {
alert("Error in appendChosenBenefit method: " + ex.message);
}
}

function ChangeNoteButtonClass() {
try {

var buttonControl = $('#notescontrol').find('a');

buttonControl.attr('class', 'addnote primary btn btn-primary commentbutton');
buttonControl.text("Add Comment / Document");
buttonControl.width(210);
}
catch (ex) {
alert("Error in ChangeNoteButtonClass method: " + ex.message);
}
}

window.addEventListener('load', updateViewIdea);


/* $(document).ready(function (){
updateViewIdea();
}); */

/* window.onload = function() {
debugger;
updateViewIdea();
}; */


$('.page-heading').parent(".container").addClass("main-block");

Reply
Oliver Rodrigues responded on 29 May 2019 3:25 AM
My Badges
Suggested Answer

the last few lines which would be what triggers your code is commented out

can you try the little piece of code that I sent previously? 

Reply
Microsoft Dynamics 365 Consultancy responded on 29 May 2019 3:38 AM
My Badges

Dear i tried but not resolved

Reply
Microsoft Dynamics 365 Consultancy responded on 29 May 2019 3:40 AM
My Badges

By the way if you have BPF custom code to show BPF on dynamics portal so kindly share. I know BPF is not supported on portal.

Reply
Oliver Rodrigues responded on 29 May 2019 5:00 AM
My Badges
Suggested Answer

are you clearing the cache after changing the JS ? did you inspect the page to see if there is any errors in the console? is it only in that page the JS doesn't work.. or pretty much any page in your portal ?

what is similar to BPF would be the Web Forms: docs.microsoft.com/.../web-form-steps

Reply
Microsoft Dynamics 365 Consultancy responded on 29 May 2019 7:02 AM
My Badges

no i did not clear cache after adding custom JS code in localized content of webpage. In console there is no error. I have also another page in which this same code is working properly but in this page this is not working. I want BPF on portal like following.

Reply
Oliver Rodrigues responded on 29 May 2019 7:42 AM
My Badges
Suggested Answer

can you please try clearing the cache... yourportalurl/_services/about

you should be able to clear if you have portal admin access

use the web forms to achieve the BPF you need.. it can be displayed the names of the steps.. to get same look & feel you will need JS/CSS.. but all the basics you can get using Portal Web Form

Reply
Oliver Rodrigues responded on 24 May 2019 3:44 AM
My Badges
Suggested Answer

can you share the code?

can you try something as simple as:

$(document).ready(function () {

   alert("hello world");

});

Reply
Oliver Rodrigues responded on 29 May 2019 3:25 AM
My Badges
Suggested Answer

the last few lines which would be what triggers your code is commented out

can you try the little piece of code that I sent previously? 

Reply
Oliver Rodrigues responded on 29 May 2019 5:00 AM
My Badges
Suggested Answer

are you clearing the cache after changing the JS ? did you inspect the page to see if there is any errors in the console? is it only in that page the JS doesn't work.. or pretty much any page in your portal ?

what is similar to BPF would be the Web Forms: docs.microsoft.com/.../web-form-steps

Reply
Oliver Rodrigues responded on 29 May 2019 7:42 AM
My Badges
Suggested Answer

can you please try clearing the cache... yourportalurl/_services/about

you should be able to clear if you have portal admin access

use the web forms to achieve the BPF you need.. it can be displayed the names of the steps.. to get same look & feel you will need JS/CSS.. but all the basics you can get using Portal Web Form

Reply

SBX - Two Col Forum

SBX - Migrated JS