cancel
Showing results for 
Search instead for 
Did you mean: 

How to import packages in javascript

sandile
Champ in-the-making
Champ in-the-making
Hi

I have created a webscript that uses the dictionary service. the webscript works perfectly fine on the javascript console but when i deploy it
under the webscripts extensions folder it gives an error "Package not defined". I need help on how i would define this package in the javascript.
Below is the javascript.
Regards


var ctx=Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var qname = Packages.org.alfresco.service.namespace.QName;
var def = Packages.org.alfresco.service.cmr.dictionary;
var ns = Packages.org.alfresco.service.namespace.NamespaceService;
var iterator = Packages.java.util.Iterator;
//var ListOfValuesConstraint = Packages.org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
var dictionaryService = ctx.getBean("DictionaryService");




                              // — Project Type Constraints —
                              
var projTypeConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','projType");
var ProjTypeListOfValuesConstraint=dictionaryService.getConstraint(projTypeConstraint).constraint.getAllowedValues();

var ProjTypeList = String(new java.lang.String(ProjTypeListOfValuesConstraint));
ProjTypeList = ProjTypeList.substring(1,ProjTypeList.length );

var printProjTypeList ='';

var tokens=ProjTypeList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
  var valProjTypeList = tokens.replace(']','');

      printProjTypeList = printProjTypeList +'<option value="List'+i+'">'+valProjTypeList+'</option>'; 

 
}

                              // — Financial Year Constraints —
                              
var finYearConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','finYear");
var finYearListOfValuesConstraint=dictionaryService.getConstraint(finYearConstraint).constraint.getAllowedValues();

var finYearList = String(new java.lang.String(finYearListOfValuesConstraint));
finYearList = finYearList.substring(1,finYearList.length);

var printfinYearList  ='';

var tokens=finYearList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
  var valfinYearList = tokens.replace(']','');

  
      printfinYearList = printfinYearList +'<option value="List'+i+'">'+valfinYearList+'</option>'; 

 
}
                              // — FP_TM Constraints —

var FP_TMCostraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','FP_TM");
var FP_TMListOfValuesConstraint=dictionaryService.getConstraint(FP_TMCostraint).constraint.getAllowedValues();


var FP_TMList = String(new java.lang.String(FP_TMListOfValuesConstraint));
FP_TMList= FP_TMList.substring(1,FP_TMList.length );

var printFP_TMList ='';

var tokens=FP_TMList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
  var valFP_TMList = tokens.replace(']','');


      printFP_TMList = printFP_TMList +'<option value="List'+i+'">'+valFP_TMList+'</option>'; 

    }
                              // — Region Type Constraints —
                              
var regionTypeConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','regionType");
var regionTypeListOfValuesConstraint=dictionaryService.getConstraint(regionTypeConstraint).constraint.getAllowedValues();

var regionTypeList = String(new java.lang.String(regionTypeListOfValuesConstraint));
regionTypeList= regionTypeList.substring(1,regionTypeList.length );

var printregionTypeList ='';

var tokens=regionTypeList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valregionTypeList = tokens.replace(']','');

      printregionTypeList = printregionTypeList +'<option value="List'+i+'">'+valregionTypeList+'</option>'; 

    }
                              // — Department Constraints —
                              
var departmentListConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','departmentList");
var departmentListListOfValuesConstraint=dictionaryService.getConstraint(departmentListConstraint).constraint.getAllowedValues();

var departmentList = String(new java.lang.String(departmentListListOfValuesConstraint));
departmentList= departmentList.substring(1,departmentList.length );

var printdepartmentList ='';

var tokens=departmentList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valdepartmentList = tokens.replace(']','');

      printdepartmentList = printdepartmentList +'<option value="List'+i+'">'+valdepartmentList+'</option>'; 

}
                              // — Project Classification Constraints —
var projectClassificationConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','projectClassification");
var projectClassificationListOfValuesConstraint=dictionaryService.getConstraint(projectClassificationConstraint).constraint.getAllowedValues();

var projectClassificationList = String(new java.lang.String(projectClassificationListOfValuesConstraint));
projectClassificationList = projectClassificationList.substring(1,projectClassificationList.length );

var printprojectClassificationList ='';

var tokens=projectClassificationList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valprojectClassificationList = tokens.replace(']','');

    var number = parseInt(valprojectClassificationList, 0);
 
  
  
      printprojectClassificationList = printprojectClassificationList +'<option value="List'+i+'">'+valprojectClassificationList+'</option>'; 
   
}
   
                              // — Project Status Constraints —
var projectStatusConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','projectStatus");
var projectStatusListOfValuesConstraint=dictionaryService.getConstraint(projectStatusConstraint).constraint.getAllowedValues();

var projectStatusList = String(new java.lang.String(projectStatusListOfValuesConstraint));
projectStatusList= projectStatusList.substring(1,projectStatusList.length );

var printprojectStatusList ='';

var tokens=projectStatusList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valprojectStatusList = tokens.replace(']','');

 
      printprojectStatusList = printprojectStatusList +'<option value="List'+i+'">'+valprojectStatusList+'</option>'; 


    }
                              // — Capacity Type Constraints —
var capabilityTypeConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','capabilityType");
var capabilityTypeListOfValuesConstraint=dictionaryService.getConstraint(capabilityTypeConstraint).constraint.getAllowedValues();

var capabilityTypeList = String(new java.lang.String(capabilityTypeListOfValuesConstraint));
capabilityTypeList= capabilityTypeList.substring(1,capabilityTypeList.length );

var printcapabilityTypeList ='';

var tokens=capabilityTypeList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valcapabilityTypeList = tokens.substring(0,5);

   var number = parseInt(valcapabilityTypeList, 0);

 
    if (number > 0)
{
  printcapabilityTypeList = printcapabilityTypeList +'<option value="List'+i+'">'+tokens+'</option>'; 
      }
}


                              // — Cost Centre List Constraints —
var costCenteListConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','costCenteList");
var costCenteListListOfValuesConstraint=dictionaryService.getConstraint(costCenteListConstraint).constraint.getAllowedValues();

var costCenteList = String(new java.lang.String(costCenteListListOfValuesConstraint));
costCenteList= costCenteList.substring(1,costCenteList.length );

var printcostCenteList ='';

var tokens=costCenteList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valcostCenteList = tokens.substring(0,5);

    var number = parseInt(valcostCenteList, 0);
 
    if (number > 0)
    {
      printcostCenteList = printcostCenteList +'<option value="List'+i+'">'+tokens+'</option>'; 

    }
 
   }

                              // — Project Clus Constraints —
var projectClusterConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','projectCluster");
var projectClusterListOfValuesConstraint=dictionaryService.getConstraint(projectClusterConstraint).constraint.getAllowedValues();

var projectClusterList = String(new java.lang.String(projectClusterListOfValuesConstraint));
projectClusterList= projectClusterList.substring(1,projectClusterList.length );

var printprojectClusterList ='';

var tokens=projectClusterList.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength; ++i)
{
     var valprojectClusterList = tokens.replace(']','');


      printprojectClusterList = printprojectClusterList +'<option value="List'+i+'">'+valprojectClusterList+'</option>'; 

    }                        // — Project Customer Constraints —
                              
var projectCustomerConstraint = qname.createQName("http://www.stratumconsutling.co.za/projservconstriants/content/1.0','projectCustomer");
var projectCustomerListOfValuesConstraint=dictionaryService.getConstraint(projectCustomerConstraint).constraint.getAllowedValues();

var projectCustomer = String(new java.lang.String(projectCustomerListOfValuesConstraint));
projectCustomer= projectCustomer.substring(1,projectCustomer.length );

var printprojectCustomer ='';

var tokens=projectCustomer.split(',');
var arrayLength = tokens.length;

for (var i = 0; i < arrayLength;i++)
{
     var valprojectCustomer = tokens.substring(0,110);

  var number = parseInt(valprojectCustomer, 0);

  if (number > 0)
   {
   printprojectCustomer = printprojectCustomer +'<option value="List'+i+'">'+tokens+'</option>'; 

    }

}


var wgroup = people.getPeople(null);






var result='';

if (wgroup == undefined)
{
   status.code = 404;
   status.message = "Group not found";
   status.redirect = true;
}
else
{
   model.all_people = wgroup;
}

var cuser = person;
if (cuser == undefined)
{
   status.code = 404;
   status.message = "Group not found";
   status.redirect = true;
}
else
{
   model.c_user = cuser;
}

// Get the collection of people in Sourcing Requests

var all_members = people.getMembers(people.getGroup("GROUP_Project_Managers"));
if (all_members == undefined)
{
   status.code = 404;
   status.message = "Group not found";
   status.redirect = true;
}
else
{
   model.projectmanagers = all_members;
}


if(companyhome.hasAspect("glo:globalSettings"))
{
   var proj = companyhome.properties["glo:finQuarter"];
   
   if (proj == undefined)
   {
      status.code = 404;
      status.message = "Project Type not found";
      status.redirect = true;
   }
var projectManOptions =proj;

}else{
var projectManOptions ='';
}

if (companyhome.hasAspect("glo:globalSettings"))
{

   var gQuarter = companyhome.properties["glo:finQuarter"];
   if (gQuarter == undefined)
   {
      status.code = 404;
      status.message = "Quarter not found";
      status.redirect = true;
   }
  var QUARTER =gQuarter;
   model.QUARTER = QUARTER;

   var gYear = companyhome.properties["glo:finYear"];
   if (gYear == undefined)
   {
      status.code = 404;
      status.message = "Fin Year not found";
      status.redirect = true;
   }
  var YEAR=gYear;
   model.YEAR = YEAR;

   var gReview = companyhome.properties["glo:finReview"];
   if (gReview == undefined)
   {
      status.code = 404;
      status.message = "Review not found –Test–";
      status.redirect = true;
   }
 
  var REVIEW= gReview;
   model.REVIEW = REVIEW;
}
else
{
   model.quarter = "";
   model.year = "";
}
model.ProjServNumber = args.ProjServNumber;
model.ProjectShortDescription = args.ProjectShortDescription;
model.ProjectLongDescription = args.ProjectLongDescription;

model.ProjServNumber = args["ProjServNumber"];
model.ProjectShortDescription = args["ProjectShortDescription"];
model.ProjectLongDescription = args["ProjectLongDescription"];



model.printProjTypeList = printProjTypeList;
model.printfinYearList = printfinYearList;
model.printFP_TMList = printFP_TMList;
model.printregionTypeList = printregionTypeList;
model.printdepartmentList = printdepartmentList;
model.printprojectClassificationList = printprojectClassificationList;
model.printprojectStatusList = printprojectStatusList;
model.printcapabilityTypeList = printcapabilityTypeList;
model.printcostCenteList = printcostCenteList;
model.printprojectClusterList = printprojectClusterList;
model.printprojectCustomer = printprojectCustomer;

1 REPLY 1

avyaznikov
Champ in-the-making
Champ in-the-making
Due to security concerns, the
Packages
root scope object is only available for web script implementations placed into the Java classpath.