Dynamically changing text - text

I have a text component called txtUsername and I can't for the life of me change it to show "Ryan."
This is what I've tried:
Linked the text component to the variable user like this.
My JS script:
var username = "Ryan";
var user : UI.Text;
// set username text
function SetUsernameText() {
user = GetComponent(UI.Text);
user.text = username;
}

you don't need to use GetComponent(UI.Text) since you already attached that gameobject in the inspector, try this:
var username = "Ryan";
var user : UI.Text;
// set username text
function SetUsernameText() {
user.text = username;
}

Related

How to set multiple values into a client side people picker

i have a list with a people picker column which takes multiple inputs.I have a form created using content editor web part in which i have a client side people picker how to set multiple values into a client side people picker using jsom
Normally you define client people control in HTML:
<div id="control" title="Users" spclientpeoplepicker="true"></div>
Then you need to initialize it.
To initialize it properly you need to assure that these javascripts files are loaded: autofill.js, clienttemplates.js, clientforms.js, clientpeoplepicker.js
JavaScript set control value code:
Entities are validate automatically with function AddUserKeys
var userField = $("input[id$='ClientPeoplePicker_EditorInput']").get(0); // simplified user control search, real word scenario, first search proper row in your form
var peoplepicker = SPClientPeoplePicker.PickerObjectFromSubElement(userField);
peoplepicker.AddUserKeys("Login1"); // or display name
peoplepicker.AddUserKeys("Login2");
JavaScript init control code:
SP.SOD.loadMultiple(['autofill.js', 'clienttemplates.js', 'clientforms.js', 'clientpeoplepicker.js'], registerControls);
function registerControls() {
initPeoplePicker('control');
}
function initPeoplePicker (id, user) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User'; //,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['Width'] = '311px';
// use code below to init controls with selected user
/*
var users = new Array(1);
var defaultUser = {};
defaultUser.AutoFillDisplayText = user.Value;
defaultUser.AutoFillKey = user.get_loginName();
defaultUser.Description = user.get_email();
defaultUser.DisplayText = user.get_title();
defaultUser.EntityType = "User";
defaultUser.IsResolved = true;
defaultUser.Key = user.get_loginName();
defaultUser.Resolved = true;
users[0] = defaultUser;
*/
// Render and initialize the picker.
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
SPClientPeoplePicker_InitStandaloneControlWrapper(id, null/*users*/, schema);
}

Using ServiceStack Ormlite global filters with Session

I want to alter the example found here so that modifyby is populated with the session's username every time a change is made. Is this possible?
You would need singleton access to access the UserName which you would need to populate in either the ReqeustContext or ASP.NET's HttpContext.Current.Items Dictionary, e.g:
GlobalRequestFilters.Add((req,res,dto) => {
RequestContext.Instance.Items["UserName"] = req.GetSession().UserAuthName;
});
Which you can access from inside your UpdateFilter, e.g:
OrmLiteConfig.UpdateFilter = (dbCmd, row) => {
var auditRow = row as IAudit;
var userName = RequestContext.Instance.Items["UserName"] as string;
if (auditRow != null)
auditRow.UserName = userName;
};
Note: the "UserName" will only work within the context of a HTTP Request.

Xpage custom inotes configuration to get profile document field

I have customized the inotes,as I wanted to add a button in "mailread",I mean inside the toolbar when the user opens the mail.as shown in image.
The fuctionality behind the this button is I wanted to go to other window with specified or hard Coded database name to open in othe window.
The code in Custom_js_Lite
code:
function Custom_Scene_Actions_Lite(s_MenuID)
{
if (-1 == s_MenuID.indexOf("mailread"))
return false;
// Add the button
var add1 = [{title:"custom-button", find_id: "print",class:"test", id: "sync", before: false,
action:"openDatabase{}", help_text:"custom-button" }];
addActionsLite( s_MenuID, true, add1);
}
// Calling function onclick.
function openDatabase(){
var unids = API_GetSelectedDocs_Lite();
var server = location.host;
var temp = location.pathname.substr(1, location.pathname.length);
var pos = temp.toLowerCase().indexOf(".nsf");
var database = temp.substr(0, pos + 4);
window.open("http://localhost/example.nsf/home.xsp?server="+server+"&db="+database+"&mailDocId="+unids);
In above code window.open, Opens the given link with selected unids which is getting from "API_GetSelectedDocs_Lite();" but the database name is hard coded that is "example.nsf";
So Instead of hardcoding the database name,I am just wondering to save the database name once profile document of that curent user's mail database, So it would help me get the database name from profile document to open it according.
I am not sure,If I can retrieve the the profile document field in subforms, custom inotes.
I need some idea how to retrieve the profile document in mail database with custom_js_lite.
Or i would really like to know if there is any other way to acheive this.
I got the solution for this.
I have just retrieved the profile document named "iNotesProfile" and add the new field in it "db_name" from my xpage button the code to update it profile document is:
var currdb:NotesDatabase = session.getDatabase(session.getServerName(),"mail/abc.nsf");
var doc:NotesDocument = currdb.getProfileDocument("iNotesProfile", "");
doc.replaceItemValue("db_name",database.getFileName());
doc.save();
This script edits the "iNotesProfile" profile document of the current user and sets the current database name inside the "db_name" field. Now we have set the database base in document which can be used from the mail database.
Now the task is to get the database name on click of custom-button.In Custom_js_Lite the code is:
function Custom_Scene_Actions_Lite(s_MenuID)
{
if (-1 == s_MenuID.indexOf("mailread"))
return false;
// Add the button //
var add1 = [{title:"custom-button", find_id: "print",class:"test", id: "sync", before: false,
action:"openDatabase{}", help_text:"custom-button" }];
addActionsLite( s_MenuID, true, add1);
}
function openDatabase(){
var unids = API_GetSelectedDocs_Lite();
var server = location.host;
var temp = location.pathname.substr(1, location.pathname.length);
var pos = temp.toLowerCase().indexOf(".nsf");
var database = temp.substr(0, pos + 4);
var mailFilePath = API_GetMailfilePath_Lite();
var db_name = '#{{#GetProfileField("iNotesProfile";"db_name")};jsData}';
if(db_name == ""){
alert("Database is not configured! Contact Administrator.");
}else{
window.open("http://localhost/"+db_name+"/home.xsp?server="+server+"&db="+database+"&mailDocId="+unids);
}
So we are now able to find the database name which is stored in iNotesProfile document by #{{#GetProfileField("iNotesProfile";"db_name")};jsData} and can be use it to go to that database.

Xpages java script server side does not update the field in form

case : Update field after select the customer name:
setting : 1 setting view that consist of database path :
DbServer: ServerOne/pcs
Directory: office
Database name : Customer.nsf
this xpages have a datasource inside, it call "document1"
// get the database path :
var vw3:NotesView=database.getView("Setting Path");
var doc3:NotesDocument=vw3.getFirstDocument();
var server:string = doc3.getItemValueString("DbServer");
var DName:string=doc3.getItemValueString("DbName");
var Directory:string=doc3.getItemValueString("Directory");
var DBName:string= Directory+"\\" +DName;
var db:NotesDatabase = session.getDatabase(server, DBName, false);
var vw:NotesView = db.getView("All Customer");
var doc:NotesDocument=vw.getDocumentByKey(document1.getValue("Customer"),true);
if (doc !=null) {
document1.setValue("Contact", doc.getItemValueString("Contact"));
document1.setValue("Telephone", doc.getItemValueString("Phone"));
document1.setValue("Fax", doc.getItemValueString("Fax"));
document1.setValue("Email", doc.getItemValueString("Email"));
}
Problem :
The field doesn't update and get the value from "customer" database.
I see a series of problems in your code:
Bind your input field to a scope variable, not to the document itself. It is a search string in the beginning, not part of the new document.
You don't check for the case that the customer wasn't found, so you never know if that was the issue.
I would rather use an URL and resolve instead of server / path / database (but that's a little style
So something like (typed off my head, will contain typos):
var vw3:NotesView=database.getView("Setting Path");
var vwe3 = vw3.getFirstEntry();
var db = session.resolve(vwe.entries[0]);
var vw:NotesView = db.getView("All Customer");
var doc:NotesDocument=vw.getDocumentByKey(viewScope.customer,true);
if (doc !=null) {
viewScope.result = doc.getUniversalID();
document1.setValue("Contact", doc.getItemValueString("Contact"));
document1.setValue("Telephone", doc.getItemValueString("Phone"));
document1.setValue("Fax", doc.getItemValueString("Fax"));
document1.setValue("Email", doc.getItemValueString("Email"));
doc.recycle()l
} else {
viewScope.result = "Not found!";
}
// ADD recycle() calls here!!!
Bind a display only field to viewScope.result, so you have a better idea what is happening. Your view must be sorted and indexed by customer name.
Of course you could use the OpenNTF dialog list control instead.

NotesRichTextItem.getMIMEEntity() always returns null

I have a notes form with a rich text field on it, called "Body". I've set the "Storage" property of the field to "Store contents as HTML and MIME".
Now, I am creating a new document with that form in the Notes Client.
However, if I try to access the rich text field's value in SSJS with NotesRichTextItem.getMIMEEntity(), it always returns null.
Am I missing something?
Thank you for your help in advance.
Update 2: 02/12/2015
I did some more testing and I found the cause, why it won't recognize the rich text field as MIME Type, but rather always returns it as RICH TEXT:
The cause is me accessing the database with "sessionAsSigner" rather than just using "database".
If I remove "sessionAsSigner" and use "database" instead, making the XPage unavailable to public access users, so, I am forced to log in, the code recognizes it as MIME Type and I can get a handle on NotesMIMEEntity.
Unfortunately, the XPage has to be available to public access users and I have to use sessionAsSigner.
When I open the document properties and I look at the rich text field, I can see that the "Field Flags" are "SIGN SEAL". My guess is, that's why sessionAsSigner doesn't work, but it is just a guess.
Any ideas?
Update 1: 02/12/2015
Here is the code I am using in my SSJS:
var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;
var sServer = session.getServerName();
oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();
//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))
//Get body text
var oItem:NotesItem = oDocMailProfile.getFirstItem("Body");
var entity:NotesMIMEEntity = oItem.getMIMEEntity();
//Create email body
var tmp = entity.getContentAsText();
//Replace <part2> with part 2 of the password
tmp = #ReplaceSubstring(tmp, "<part2>", sPWPart2);
//Set content of Body field as MIME type
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
//Send email
oDocMail.send();
As I mentioned before, I've also tried:
var oDBCurrent:NotesDatabase = sessionAsSigner.getDatabase(session.getServerName(), session.getCurrentDatabase().getFilePath());
var oVWMailProfiles:NotesView = oDBCurrent.getView('$vwSYSLookupEmailProfiles');
var oVWPWResetRecipient:NotesView = oDBCurrent.getView('$vwPWPMLookupPWResetNotificationProfiles');
var oDocPWResetRecipient:NotesDocument = null;
var oDocMailProfile:NotesDocument = null;
var oDocMail:NotesDocument = null;
var sServer = session.getServerName();
oDocPWResetRecipient = oVWPWResetRecipient.getDocumentByKey(sServer, true);
oDocMailProfile = oVWMailProfiles.getDocumentByKey('.MailTemplate', true);
oDocMail = oDBCurrent.createDocument();
//Set default fields
oDocMail.replaceItemValue('Form', 'Memo');
oDocMail.replaceItemValue('Subject', oDocMailProfile.getItemValueString('iTxtSubject'));
oDocMail.replaceItemValue('SendTo', oDocPWResetRecipient.getItemValue('iNmesRecipients'))
//Get body text
var entity:NotesMIMEEntity = oDocMailProfile.getMIMEEntity('Body');
//Create email body
var tmp = entity.getContentAsText();
//Replace <part2> with part 2 of the password
tmp = #ReplaceSubstring(tmp, "<part2>", sPWPart2);
//Set content of Body field as MIME type
var body = oDocMail.createMIMEEntity();
var stream = session.createStream();
stream.writeText(tmp);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
//Send email
oDocMail.send();
Try calling sessionAsSigner.setConvertMime(false)
You get the MIMEEntity from the document, not from the Richtext item. See an example here (starting at line 103): https://github.com/zeromancer1972/OSnippets/blob/master/CustomControls/ccSnippets.xsp
You should set the session to not convert MIME to RichText.
Add this at the start of your code.
session.setConvertMime(false);

Resources