cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to include javascript in nintex task form

Jump to solution

have a nintex workflow running on a document set in a document library in SharePoint. I want to provide the documents name in the task form, so that user can approve after seeing the documents. I have the below script running in my developer tool to fetch the records inside a document set. I would like to know how to implement it inside a Task form and if I have a field in Nintex Task form having document set name, how should i bind it inside my code. And After all is done, How am I going to display it on the Nintex form. The question may be very basic but I have just started with Nintex and trying to find all it can offer. 

var folderUrl = "/sites/portalmgmt/DS_Test/Powai";

var listTitle = "DS_Test";

var kk;

function main()

{ SP.SOD.executeFunc('sp.js', 'SP.ClientContext', loadConstants); }

function loadConstants()

{ var ctx = new SP.ClientContext.get_current(); this.site = ctx.get_site(); ctx.load(this.site); this.web = ctx.get_web(); ctx.load(this.web);   ctx.executeQueryAsync(Function.createDelegate(this, function() { onSuccess(ctx); }), Function.createDelegate(this, this.onFail)); }

function onSuccess(ctx) { kk = ctx; var olist = ctx.get_web().get_lists().getByTitle('DS_Test')   var qry = SP.CamlQuery.createAllItemsQuery(); qry.set_folderServerRelativeUrl(folderUrl); var items = olist.getItems(qry); ctx.load(items, 'Include(File)'); ctx.executeQueryAsync( function() { innerSuccess(items); }, innerError); } function onFail(sender, args) { console.log(args.get_message()); }

function innerSuccess(items) { for (var i = 0; i < items.get_count(); i++) { var file = items.get_item(i).get_file(); console.log(file.get_name()); } }

function innerError(sender, args) { console.log(args.get_message()); }

main();

Tags (2)
0 Kudos
Reply
5 Replies
Highlighted
Workflow Hero

Re: How to include javascript in nintex task form

Jump to solution

Hi Ankit,

first of all i recommend to watch this little tutorial video from nintex explaining in general how to add JS in a nintex form: Video: Writing Custom JavaScript In Nintex Forms for SharePoint

Afterwards you can find a lot of examples here in the community that will give you some "real world" examples, e. g. : Re: Nintex Forms and JavaScript basics (hit the Search with "Javascript" and you will find a lot more)

And if you still have any questions, just ask again =)

Greetings

Philipp

Reply
Not applicable

Re: How to include javascript in nintex task form

Jump to solution

Hi Philip,

Thanks for replying!!

I followed the same procedure as mentioned in the video and other docs and was able to run simple javascript/jquery code. However, When I am trying a complex one I don't get the desired result. For example, in below code, I don't get the alert after I load the clientcontext. Is there a way for fetching sp client context in Nintex or am I doing something wrong. If I write the alert part before clientContext.load(web), I get the alert. This is just a piece of code I am trying to get it work. The actual code is bit complex and hence I fear will run into many other issues. Kindly advice.

NWF.FormFiller.Events.RegisterAfterReady(function () {

var clientContext = new SP.ClientContext.get_current();

var web = clientContext.get_web();var pollSP;

var folderUrl = "sites/Test/Proposal/Test_Ankit22";

var listTitle = "Proposal";

var kk;

NWF.FormFiller.Events.RegisterAfterReady(function () {

    pollSP = setInterval(checkSPLoad, 500);

});

function checkSPLoad() {

    if (clientContext) {

        window.clearInterval(pollSP);

        onSPLoad();

    }

}

});

function onSPLoad() {

clientContext.load(web);

alert("Pass Result2");

clientContext.executeQueryAsync(Function.createDelegate(this, function() { onSuccess(clientContext); }), Function.createDelegate(this, this.onFail));

}

Thanks,

Ankit

Reply
Workflow Hero

Re: How to include javascript in nintex task form

Jump to solution

You can use your Browser Developer Tools (F12) to see if your script has produced any errors. Does it show anything useful?

Reply
Not applicable

Re: How to include javascript in nintex task form

Jump to solution

Ok!! Finally after following all blogs and videos I was able to run major part of my code in Nintex Form. Thanks for directing me to the right place. I was getting all the desired result until I got stuck to one last point where I am stuck and I have tried all possible way. The scenario is I am getting a set of name(file names in a document set). I am able to alert out these names. I want these names to be binded to the nintex form inside a text box/multiple box anywhere on the form which is getting loaded. Steps I am following for this:

A) Copy a singleText field in the form.
b) Declare the ClientID Name of the field.
c) Pass the value in the control using the ID and Jquery.
d) Run the code.

I am unable to get the value(inputfile) in the text box(id as FileName) as I am getting in the alert. Below is the piece of code where I am facing the issue. Is the declaration wrong?? What am I missing?? Please help!!

function innerSuccess(items) {
try{
alert("Item Count in Current Folder:"+items.get_count());

for (var i = 0; i < items.get_count(); i++) {
var file = items.get_item(i).get_file();
alert("Files in the Current Folder:" +file.get_name());
var inputfile= file.get_name();

//below line return nothing
//NWF$('#FileName').val(inputfile);
}
}

catch()

{}

}

Reply
Workflow Hero

Re: How to include javascript in nintex task form

Jump to solution

Hi Ankit,

NWF$('#FileName').val(inputfile) your selector is wrong. In Nintex Form you have to write NWF("#" + FileName) if FileName is the ID variable of the field you want to write in.

Because what you configured in your control is to "Store JS ID in a variable" and you need to call that variable you entered right now.

Don't forget to use the developer tools of your browser to debug your JS code

Greetings

Philipp

0 Kudos
Reply