0

I was trying to help the below quention, with a simple example. could-anyone-provide-aikau-form-example-with-data-loading

Basically, I would do a repo request when the form dialog loads and wanted to display the document libray noderef in the dialog. So I called makeRepoRequest() during dialog load, but the network tab throws 401 error.

Please let me know, what is wrong with this sample?

/* studentForm.get.js */
function makeRepoRequest()
{
    var alfDestination = "something";


    var site = page.url.templateArgs.site;
    var result = remote.call("/slingshot/doclib/container/" + site + "/documentLibrary");
    return result.status.code;
    if (result.status.code == status.STATUS_OK) {
        alfDestination = JSON.parse(result).container.nodeRef;
    }
}

var formControls = [
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      name: "name1",
      label:"Name",
      placeHolder:"Enter Name Here",
      visibilityConfig: {
        initialValue: true
      }
    }
  },
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      label:"Age",
      name: "age",
      placeHolder:"Enter Age Here",
      visibilityConfig: {
        initialValue: true
      }
    }
  }
  ,
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      label:"NodeRef",
      name: "nodeRef",
      visibilityConfig: {
        initialValue: true
      },
      value : makeRepoRequest()
    }
  }
];

var showDialog = {
  name: "alfresco/buttons/AlfButton",

  config: {
    readOnly:"true",
    id:"dialog1",
    label: "Create New Student",
    additionalCssClasses: "call-to-action",
    publishTopic: "ALF_CREATE_FORM_DIALOG_REQUEST",
    publishPayloadType: "PROCESS",
    publishPayload: {
      dialogTitle: "Student Form",
      dialogConfirmationButtonTitle: "Register",
      dialogCancellationButtonTitle: "Cancel",
      formSubmissionTopic: "ALF_CRUD_CREATE",
      formSubmissionPayloadMixin: {
        url: "api/type/cm%3Astudent/formprocessor"
      },
      fixedWidth: true,
      widgets: formControls
    }
  }
};

model.jsonModel = {
widgets :[showDialog 
         ],
services : [
            "alfresco/dialogs/AlfDialogService",
            "alfresco/services/CrudService" 
        ]     
};
Community
  • 1
  • 1

2 Answers2

1

A 401 status code indicates that the user is not authenticated. Where are you running on this code? Is it on Share or a standalone Aikau client? Is the user logged in? Do they have the necessary permissions to access that API? Are they a member of the site? What privacy does the site have?

Dave Draper
  • 1,837
  • 11
  • 25
0

i have tested your code with giving my site name statically(ex demo ) in alfreso sdk , it working fine and gives me nodeRef using this code

function makeRepoRequest()
{
var alfDestination = "something";


var site = "demo";
var result = remote.call("/slingshot/doclib/container/" + site + "/documentLibrary");

if (result.status.code == status.STATUS_OK) {
    alfDestination = JSON.parse(result).container.nodeRef;
}
 return alfDestination ;
}

have you tested that whatever site name is getting is correct? i have tested this code using browser url.

Sanjay
  • 2,481
  • 1
  • 13
  • 28