Pages

Showing posts with label Sharepoint Code. Show all posts
Showing posts with label Sharepoint Code. Show all posts

Thursday, December 15, 2022

Hide Sharepoint Web Parts using Javascript

 I have placed List webpart to filter some value then pass to other Webpart to display filtered Content.

The following code will hide the List webpart then users will not see those Hidden Value.

you just find that webpart ID and add in the following code.

Add this to Script Editor Webpart. Publish the page then the web part will be hidden.


Work Around Code:

<script type="text/javascript">

document.getElementById('MSOZoneCell_WebPartWPQ6').style.display='none';

</script>

Friday, February 1, 2019

Sharepoint JSOM client object model code to retrieve other list item in Nintex Form

When using the SharePoint JavaScript client object model, your code needs to be broken up into two parts: the first part specifies what you want to get, and involves you loading queries and commands into an SPClientContext object; the second part lets you manipulate the results of the query to SharePoint, and runs as an asynchronous callback of the query execution.
  1. Create your context, specify which lists you want to access, etc.
  2. Run clientContext.executeQueryAsync() (where clientContext is an SP.ClientContextobject), and pass in delegate functions to run on success or failure
  3. In your "onSuccess" delegate function, you can work with the results of the commands you loaded up in step 1



function FormLoading()
{
console.log('Inside Jcode Form Loading Calls');
NWF$("#" + JSLeaveType).change(function()
{

EmpLeaveBalance();
});
}

function  EmployeeLeaveBalance()
{
try
{
NWF$("#" + JSLeaveBalance).val("");
var clientContext = SP.ClientContext.get_current(); 
var web = clientContext.get_web(); 

var oList = clientContext.get_web().get_lists().getByTitle("LeaveSBalanceS");

var newCRUsername = varCRUsername.replace('downlevelTextBox','upLevelDiv');
var varCRUsernamevalue= NWF$('#' + newCRUsername).find('span.ms-entity-resolved').attr('title');
var lists = new SPAPI_Lists('');
var userprofiles= new SPAPI_UserProfile('');
var currentUserProfile = getUserProfileInfo(userprofiles,varCRUsernamevalue); 
var userFullName = getFullName(currentUserProfile);
//alert('UserFullName  '+userFullName);
//var varCurrentUser = clientContext.get_web().currentUser();
//var accountname = currentUser.get_title();
//console.log("accountname --> " + accountname);
var camlQuery = new SP.CamlQuery();
/* Use a CAML query to filter your results */
camlQuery.set_viewXml( +userFullName+ );

//camlQuery.set_viewXml('' + userFullName + '' + (new Date()).getFullYear() + '');
/* get the list item collection from the list */
        var oListItems = oList.getItems(camlQuery);
/* tell SharePoint to load the list items */
clientContext.load(oListItems);
  
//var LeaveType=NWF$("#" + JSLeaveType).val();   
var LeaveType=NWF$("#" + JSLeaveType + ' option:selected').text(); //Nintex form control is lookup field then get selected text
//clientContext.load(ListItem,'Include(AnnualLeave)','Include(MedicalLeave)'); 
/* execute the query to get the loaded items */

    clientContext.executeQueryAsync(
        /* onSuccess Function */
        Function.createDelegate(this, function () {
            /* 
            now that the query has run, you can get an enumerator 
            from your list item collection 
            */
            var arrayListEnum = oListItems.getEnumerator();
            var ids = [];
            while (arrayListEnum.moveNext()) {
console.log("New Inside While array loop");
//console.log(arrayListItem.get_current());
var listItem = arrayListEnum.get_current();
console.log(listItem.get_item('Title'));
console.log(listItem.get_item('AnnualLeave'));
console.log(listItem.get_item('MedicalLeave'));
//var varLeaveTypeName = NWF.RuntimeFunctions.parseLookup(NWF$('#'+JSLeaveType).val(),true); // Not working
var varLeaveTypeName =NWF$('#'+ JSLeaveType + ' option:selected').text();
console.log("varLeaveTypeName with Space  "+varLeaveTypeName);
varLeaveTypeName=varLeaveTypeName.replace(/\s+/g, ''); //Remove Space Javascript varaible
console.log("varLeaveTypeName without space "+varLeaveTypeName);
var varLeaveBalance = listItem.get_item(varLeaveTypeName);
console.log(varLeaveBalance);
            }
//console.log("Outside While array loop");
            
        }),
        /*onFailure Function*/
        Function.createDelegate(this, function (sender, args) {
            alert("Whoops: " + args.get_message() + " " + args.get_stackTrace());
        })
);
 }
catch(e)
{
alert("EmployeeLeaveBalance ERROR is " + e);
}
 }