Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Javascript in CEWP on Project Site error

$
0
0

Hi All,

Currently I am trying to create a dynamic link to a sharepoint list on the main site from the Project Site. The dynamic link basically reads the Project name and then accordingly creates a link to the sharepoint list with filter in the URL. However the code for creating the dynamic link in CEWP does not work, its either taking over the entire page and creating a new page with just the URL on it, or I get undefined value.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script><script type="text/javascript">

 var i = 0;
 var ProjectUID;
 var ProjectName;
 var hrefer;
 var url_new;
 window.setTimeout(ColourCalendar, 250000);
 window.setTimeout(ColourCalendar, 1000);
 window.setTimeout(ColourCalendar, 1000);
 window.setTimeout(ColourCalendar, 1000);
 window.setTimeout(ColourCalendar, 1000);
 window.setTimeout(ColourCalendar, 1000);
 SP.SOD.executeOrDelayUntilScriptLoaded(getProjectUIDProperty, 'sp.js');

 function getProjectUIDProperty() {
                var ctx = new SP.ClientContext.get_current();
                this.web = ctx.get_web();
                this.props =  this.web.get_allProperties();
                ctx.load(this.web);
                ctx.load(this.props);
                ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));
            }


function gotProperty() {
                 ProjectUID = this.props.get_item('MSPWAPROJUID');
				 hrefer = LoadProjectData();
            }
function failedGettingProperty() {
                alert('Error: ' + args.get_message());
            }
function LoadProjectData() {
        var data = $.ajax({url: _spPageContextInfo.siteAbsoluteUrl + "/_api/ProjectData/Projects(guid'"+ ProjectUID +"')?"+ "$select=ProjectName",
									type: "GET",
									dataType: "json",
									headers: {Accept: "application/json;odata=verbose"	}
							});
        data.done(function (data,textStatus, jqXHR)
		{
			if (data.d.results == undefined) {

			ProjectName = data.d.ProjectName;
                        ColourCalendar();
						var url_new = 	'<a href ="/IT/Lists/Project%20Inventories/AllItems.aspx?FilterField1=Parent_x0020_Project_x0020_Name&amp;FilterValue1=' + ProjectName + '" target="_blank">Project Inventories - All Items </a>'
						//writeURL(url_new);
						//document.write(url_new);
        	}

        });
        data.fail(function (jqXHR,textStatus,errorThrown)
		{
            alert("Error retrieving project data: " + jqXHR.responseText);
        });



//writeURL();


}

function writeURL(url_new)
{
document.write(url_new);
}

function ColourCalendar() {

if (i < 2){
window.setTimeout(ColourCalendar, 1000);
i=i+1;
}
}
//window.onload=getProjectUIDProperty;
writeURL(url_new);
document.write(url_new);</script>

Any help would really be appreciated...

Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>