How to create an Enterprise custom field programmatically for Project Server - javascript

I want a Sharepoint 2013 app to create programmatically an Enterprise Custom Field when it runs for the first time.
I fiddled around with the following code snippet, but it's not working
var projContext = PS.ProjectContext.get_current();
function AddCustomField() {
$('#message').text('Adding Custom Field...');
var object_to_add = new PS.CustomFieldCreationInformation();
object_to_add.FieldType = CustomFieldType.Text;
object_to_add.Name = "New_one";
object_to_add.Description = "test description";
projContext.CustomFieldCollection.add(object_to_add);
}
Any help would be appreciated!

var projContext = PS.ProjectContext.get_current();
var fieldType = PS.CustomFieldType.TEXT;
var customfields = projContext.get_customFields();
var entityTypes = projContext.get_entityTypes();
var projEntity = entityTypes.get_projectEntity();
var resourceEntity = entityTypes.get_resourceEntity();
var taskEntity = entityTypes.get_taskEntity();
projContext.load(customfields);
projContext.load(entityTypes);
projContext.load(projEntity);
projContext.load(resourceEntity);
projContext.load(taskEntity);
projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
CreateField("Test", "Test", fieldType, projEntity);
function CreateField(name, description, fieldtype, entitytype) {
var customfieldInfo = new PS.CustomFieldCreationInformation();
customfieldInfo.set_description(description);
customfieldInfo.set_name(name);
customfieldInfo.set_fieldType(fieldtype);
customfieldInfo.set_entityType(entitytype);
customfields.add(customfieldInfo);
customfields.update();
projContext.load(customfields);
projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
}

Related

vRA (vRealize) help, script isn't working as it should

When I spin up a new vm the custom attributes field populates everything but one particular field. I am brand new to vRA and was told to try to fix this. I have read some documentation and watched a few videos but I am at a loss so any help would be greatly appreciated.
var customProperties = inputProperties['customProperties'];
vmName = inputProperties['resourceNames'][0];
bUID = customProperties['bPOC'];
tUID = customProperties['tPOC'];
mUID = customProperties['mPOC'];
bName = System.getModule("com.vmware.library.tasks").getNameFromuID(bUID);
mName = System.getModule("com.vmware.library.tasks").getNameFromuID(mUID);
bEmail = System.getModule("com.vmware.library.tasks").getEmailFromuID(bUID);
mEmail = System.getModule("com.vmware.library.tasks").getEmailFromuID(mUID);
tName = "";
tEmail = "";
var userName = System.getContext().getParameter("__metadata_userName");
if (tUID == "0000000") {
tName = System.getModule("com.vmware.library.tasks").getNameFromuID(userName);
tEmail = System.getModule("com.vmware.library.tasks").getEmailFromuID(userName);
}
else {
tName = System.getModule("com.vmware.library.tasks").getNameFromuNID(tUNID);
tEmail = System.getModule("com.vmware.library.tasks").getEmailFromuNID(tUNID);
}
chartfield = customProperties['chartfield'];
This is the code that they wanted me to look through and mess with. It was having issues with the tName and tEmail but the person showing me around fixed those while he was showing me how to do stuff. Any help would be greatly appreciated. Thank you

Display a waiting gif during a javascript function

I write a script to get a text file, to modify this texter file and then I import the file in our software.
The problem is that the import of the file is very slow (just this part of the script could take more than 1 minute sometime).
I would like to display a waiting gif during this process, so the user can see that the process is running, and he need to wait.
Some precision:
- It's only a javascript file with no html page
- The script is launched with a button in our software and I have access to ActiveXObject if necessary
Here is a sample code :
function importFec()
{
var iOpenDlg = 1;
var sPath = "Deskop";
var sTypes = "Fichier Texte (*.txt)|*.txt";
var sExt = "txt";
//Allow me to select a file in Windows
cheminFEC = fileDialog(iOpenDlg, sPath, sTypes, sExt);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1;
var f1 = fso.OpenTextFile(cheminFEC, ForReading);
var texte = f1.ReadAll();
var tableauFEC = [];
var tableauTest = [];
tableauFEC = texte.split(/\r\n/);
tableauTest = tableauFEC[0].split("\t");
var delimiter = "\t";
if (tableauTest.length == 1)
{
tableauTest = tableauFEC[0].split("|");
var delimiter = "|";
}
var nbColonne = tableauTest.length;
for (var i=0;i<tableauFEC.length;i++)
{
var tab = tableauFEC[i].split(delimiter);
tableauFEC[i] = new Array(25);
for (var j=0;j<nbColonne;j++)
{
tableauFEC[i][j] = tab[j];
}
}
//Make some change in the table to adapt my texte file
//Then create a new texte file C:\\FichierFEC\\FECModifie.txt
createNewFEC(tableauFEC);
var cwfConfiguration = Application.ApplicationInfo("ProgramPath")+"\\Library\\ImportFEC\\ImportFEC23032017.vgl"
var oImport = Import(ipASCII)
oImport.ImportComponents = CWImportComponents.icGeneralLedger
oImport.ASCIILayoutFile = cwfConfiguration
oImport.ASCIIDataFile = "C:\\FichierFEC\\FECModifie.txt"
//This is the function which take a long moment to execute
oImport.RunImport()
}
Thanks for your answer and explanation
I finnaly found another solution.
At the beggining of my script, I launch a .hta file with a GIF and a small texte.
At the end of my script, I close the .hta file
Thanks

JQuery multiple input fields of each row keyup function not working

Hello I am trying to make my jquery code in working order but its not working at all, I don't know whats a problem behind it but it contains multiple text boxes in multiple rows, each row calculates its own sum
Here is Fiddle link
Here is my Code
$(document).ready(function(){
$('.employee input[type="text"]').keyup(function() {
var basic_salary = parseInt($('input[name^=txtMonthlyRate]').val());
var advance_salary = parseInt($('input[name^=txtAdvance]').val());
var recover_comm = parseInt($('input[name^=txtRecovery]').val());
var sales_comm = parseInt($('input[name^=txtSales]').val());
var deduction_salary = parseInt($('input[name^=txtDeduction]').val());
var adjustment_salary = parseInt($('input[name^=txtAdjustment]').val());
var total_sum = ((basic_salary+recover_comm+sales_comm) - (deduction_salary + advance_salary)) + adjustment_salary;
$('input[name^=txtTotal]').val(total_sum);
console.log(total_sum)
);
});
The txtSales1, txtDeduction1, txtAdjustment1 variables are camel cased in your javascript, but not on the html input name. So these return NaN.
UPDATE Also, you need to set the context of what you're referring to using the second parameter of a selector function:
$('.employee input[type="text"]').keyup(function(e) {
var $scope = $(this).closest('.employee');
var basic_salary = parseInt($('input[name^=txtMonthlyRate]', $scope).val());
var advance_salary = parseInt($('input[name^=txtAdvance]', $scope).val());
var recover_comm = parseInt($('input[name^=txtRecovery]', $scope).val());
var sales_comm = parseInt($('input[name^=txtSales]', $scope).val());
var deduction_salary = parseInt($('input[name^=txtDeduction]', $scope).val());
var adjustment_salary = parseInt($('input[name^=txtAdjustment]', $scope).val());
var total_sum = ((basic_salary+recover_comm+sales_comm) - (deduction_salary + advance_salary)) + adjustment_salary;
$('input[name^=txtTotal]', $scope).val(total_sum);
});
The txttotal1 needs to be changed to txtTotal1
The fiddle needs a closing }

Uploading data & image into Google spreadsheet

I'm trying to have users fill a form and I have the form all done here
https://docs.google.com/forms/d/1mjDLcGvcVlSG0Tjfx2ZEvGdrFqvQo-ezaB1A4vaBFK8/viewform
I have read through the answers here Upload an image to a Google spreadsheet
I have two issues:
How to call the form I have, rather than the one in this code
var submissionSSKey = 'google sskey';
var docurl = 'google form url'
var listitems = ['Gender','Male','Female']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'solid','borderWidth':'10PX','borderColor':'#bbbbbb'}
function doGet() {
var app = UiApp.createApplication().setTitle('Biodata').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>89 Law School Class Alumni Biodata</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(6,2).setId('grid');
var list1 = app.createListBox().setName('list1').setWidth('130');
for(var i in listitems){list1.addItem(listitems[i])}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background','#bbbbbb').setStyleAttribute('fontSize','18px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1,'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background','#99FF99').setStyleAttribute('fontSize','12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'Name')
.setWidget(2, 1, Textbox1.addClickHandler(cliHandler2))
.setText(3, 0, 'Email')
.setWidget(3, 1, email)
.setText(4, 0, 'Image File')
.setWidget(4, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(5, 0, submitButton)
.setWidget(5, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background','yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal = e.parameter.list1;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var blob = fileBlob.setContentTypeFromExtension()
var img = DocsList.createFile(blob);
try{
var folder = DocsList.getFolder('photos');
}catch(e){DocsList.createFolder('photos');var folder = DocsList.getFolder('photos')}
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder());
var weight = parseInt(img.getSize()/1000);
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Sheet1');
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow+1, 1, 1, 4).setValues([[ListVal,textVal,Email,"https://drive.google.com/uc?export=view&id="+img.getId()]]);
var imageInsert = sheet.getRange(lastRow+1, 5).setFormula('=image("https://drive.google.com/uc?export=view&id='+img.getId()+'")');
sheet.setRowHeight(lastRow+1, 80);
var GDoc = DocumentApp.openByUrl(docurl)
GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
var inlineI = GDoc.appendImage(img);
var width = inlineI.getWidth();
var newW = width;
var height = inlineI.getHeight();
var newH = height;
var ratio = width/height;
Logger.log('w='+width+'h='+height+' ratio='+ratio);
if(width>640){
newW = 640;
newH = parseInt(newW/ratio);
}
inlineI.setWidth(newW).setHeight(newH)
GDoc.appendParagraph('IMAGE size : '+width+' x '+height+' (eventually) resized to '+newW+' x '+newH+' for PREVIEW ('+weight+' kB) ');
GDoc.appendHorizontalRule();
GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app
}
I'm getting "Cannot read property "parameter" from undefined" when I run doPost(e)
Any idea what I should do, pls? I'm kinda behind schedule
Many thanks
in relation with your 2 questions :
You can't mix a form built with FormApp and a form built using UiApp, you'll have to build the entire form using UiApp if you want to keep the file upload feature as it is. As an alternative , you can of course build the entire form using HTMLService if you are more comfortable with html...
If you try to run the doPost function from the script editor you will always get an undefined value for e since e is actually the event info that holds all the elements returned by the doGet call (also known as callback element)
I've been looking at your form and I think it should be quite easy to transpose it in UiApp since all the fields are simple textBox elements. The post you used makes use of clientHandlers to make some fields mandatory so you have all the necessary informations to build your own form.
If you want to make it "look like" your form just change the style attributes of the panel and eventually add more style attributes to some items. Available CSS like styles are viewable here.

How to add a duplicate panel in google apps script?

I am wondering how to add a duplicate panel underneath the previous existing panel ("productOtherPanel") using the "Add Product" button. I would like the new panel to be inserted below the existing "productOtherPanel" and above the "Add Product" button. I would also like this new panel to contain the same drop down list and text box as the original "productOtherPanel". I need this panel to duplicate an infinite number of times. Is this possible?
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createHorizontalPanel().setId('productOtherPanel');
var productPanel = app.createVerticalPanel().setId('productPanel');
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
var pricePerTonPanel = app.createVerticalPanel().setId('pricePerTonPanel');
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox")
.setText("$0.00");
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
productPanel.add(productList);
productOtherPanel.add(pricePerTonPanel);
pricePerTonPanel.add(pricePerTonTextBox);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
Try to see if this code is what you are looking for:
function doGet(e) {
var app = UiApp.createApplication();
var productOtherPanel = app.createVerticalPanel().setId('productOtherPanel');
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var buttonPanel = app.createVerticalPanel().setId('buttonPanel');
var button = app.createButton("Add Product");
button.addClickHandler(app.createServerHandler("addProductHandler").addCallbackElement(productOtherPanel));
app.add(productOtherPanel);
productOtherPanel.add(productPanel);
app.add(buttonPanel);
buttonPanel.add(button);
return app;
}
function addProductHandler(e) {
var app = UiApp.getActiveApplication();
var productPanel = app.createHorizontalPanel().setId('productPanel');
// Product list dropdown
var productList = app.createListBox().setName("productList").setId('productList');
productList.addItem("8:1 Compressed Blocks");
productList.addItem("8:1 Compressed Briquettes");
// Product Price Textbox
var pricePerTonTextBox = app.createTextBox().setId("pricePerTonTextBox").setName("pricePerTonTextBox").setText("$0.00");
productPanel.add(productList);
productPanel.add(pricePerTonTextBox);
var panel = app.getElementById("productOtherPanel");
panel.add(productPanel);
return app;
}

Categories