I have a list called 'quotes' and list called 'autoquotenumber'. 'autoquotenumber' only has one item id=1 which is used to keep track of the quote numbers. I would like to retrieve a column from 'numbers' list whose column name is 'lastnumber' and use it in my quotes list to populate a field called 'quote number' when entering a new item.

I have this functioning with a flow perfectly, however the time it takes for the flow to kick off is too long sometimes a couple of minutes. I would like to try to get this working with JavaScript if possible.

Unfortunately I'm still learning a lot about this, so any help I can get is appreciated.

I've been trying to piece some things together, and thought i might be getting close with this:

var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(AutoGenerate, "sp.js");

function AutoGenerate() {
    clientContext = new SP.ClientContext.get_current();
    web = clientContext.get_web();
    var list = web.get_lists().getById(_spPageContextInfo.pageListId);
    var camlQuery = new SP.CamlQuery();
    this.listItems = list.getItems(camlQuery);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
        Function.createDelegate(this, this.onQueryFailed));

function onListItemsLoadSuccess(sender, args) {
    var itemId = 1;   
    var targetListItem;
    var clientContext = new SP.ClientContext(); 
    var targetList = clientContext.get_web().get_lists().getByTitle('AutoQuoteNumberTest');
    targetListItem = targetList.getItemById(itemId);
    var AutoIncremental = "Quote-" + clientContext.load(targetListItem, 'lastnumber');
    $("input[title^='Quote Number']").val(AutoIncremental);
    $("input[title^='Quote Number']").attr('disabled', 'disabled');

function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

Unfortunately this is what I get, no number retrieved:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.