Lotus Notes - Change Value in Document from View - replace

Does anyone have code that replaces a value in selected document of a view using a customized icon on the toolbar. I remember this was done using Formulas but cannot find anymore on the web.
Thanks,
Tim

Create a custom icon in the toolbar preferences and put this code in the formula window. Show the icon in all views. While in a view, it will prompt you for the field, its type and its value. Then it will replace that value in the field without ever opening the document.
Found this in one of the public Lotus Notes forums a long time ago. If anyone knows the original creator, please name them here for credit they deserve.
REM {Get a listing of all the fields on the current document};
List := #DocFields;
REM {Possible data types to choose from.};
REM {I called Number Integer because use keyboard to select what you want with keyboard quicker.};
DataTypes := "Text" : "Date" : "Integer" : "Password" : "Name" : "Common Name" : "**** Remove Field ****" : "Text Multi Value" : "Date Multi Value" : "Integer Multi Value" : "Name Multi Value";
REM {Prompt for which field needs to be updated.};
EditField := #Prompt([OkCancelList]; "Select Field To Update"; "Select the field you wish to update:"; ""; List : "**** ADD A NEW FIELD ****");
REM {If adding a new field, prompt for the field name};
NewFieldName := #If(EditField = "**** ADD A NEW FIELD ****"; #Prompt([OkCancelEdit]; "Enter Field Name"; "Enter the name of the new field:"; ""); "");
CheckFieldName := #If(#IsMember(NewFieldName; List) & NewFieldName != ""; #Return(#Prompt([Ok]; "Already In List"; "The field " + NewFieldName + " already exists on the document.")); "");
UpdateVariable := #If(NewFieldName = ""; ""; EditField := NewFieldName);
REM {Prompt for which data type you would like the data to be};
REM {This needs to be done before value prompt to determine if the};
REM { Picklist or any prompting needs to be used.};
DataType := #Prompt([OkCancelList] : [NoSort]; "Choose Data Type"; "Please Select the correct data type or action for field: " + EditField; "Text"; DataTypes);
REM {For multi-valued fields, let the user choose the separator to use};
Separator := #If(#Contains(DataType; "Multi Value"); #Prompt([OkCancelList] : [NoSort]; "Choose Separator"; "Choose the separator to split out your multiple values"; ":"; (":" : ";" : "+" : "-" : "*")); "");
REM {Pull out the current value of the field};
CurrValue1 := #Eval(#Text(EditField));
CurrValue2 := #Abstract([TextOnly]; 254; ""; #Text(EditField));
CurrValue := #If(#IsNumber(CurrValue1) | #IsTime(CurrValue1); #Implode(#Text(CurrValue1); Separator); CurrValue2 != ""; CurrValue2; #Implode(#Text(CurrValue1); Separator));
REM {Based on what type of data is being entered different prompts will happen if any at all.};
RawValue := #If(
#Contains(DataType; "Name Multi Value"); #PickList([Name]);
#Contains(DataType; "Name"); #PickList([Name] : [Single]);
DataType = "**** Remove Field ****"; "";
#Contains(DataType; "Multi Value"); #Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + " seperated with " + Separator + " for each value."; CurrValue);
#Prompt([OkCancelEdit]; "New Value"; "Please enter the new desired value for: " + EditField + "."; CurrValue)
);
REM {If data conversion doesn't work then don't set field.};
#If(
DataType = "Date"; #If(#SetField(EditField; #TextToTime(RawValue)));
DataType = "Integer"; #If(#IsError(#TextToNumber(RawValue)); ""; #SetField(EditField; #TextToNumber(RawValue)));
DataType = "Password"; #SetField(EditField; #Password(RawValue));
DataType = "**** Remove Field ****"; #SetField(EditField; #DeleteField);
DataType = "Text Multi Value"; #SetField(EditField; #Explode(RawValue; Separator));
DataType = "Date Multi Value"; #SetField(EditField; #TextToTime(#Explode(RawValue; Separator)));
DataType = "Integer Multi Value"; #If(#IsError(#TextToNumber(#Explode(RawValue; Separator))); ""; #SetField(EditField; #TextToNumber(#Explode(RawValue; Separator))));
DataType = "Name Multi Value"; #SetField(EditField; #Explode(#Name([Canonicalize]; RawValue); Separator));
#SetField(EditField; RawValue)
);
""

Related

Parse string data according to template in qt c++

I have a string which consist of data along with spaces i want to sort this string into particular variables
eg.
" Company Name : ABC Department : TESTING";
i want to split this string and get the company name and department name to add to their particular variable
You will have a pain in the neck for achieving that taks because the data is ill formatted,
your goal is to obtain from the string something like:
Company Name = ABC
Department = TESTING
even using the method split, you need a token that you dont have...
the suggestion i can provide is to redefine those strings in something well formatted and parsable... json is a good candidate for this task
imagine this example using json objects:
QString str3 = "{\"Company Name\" : \"ABC\", \"Department\" : \"TESTING\", \"Number\" : 123, \"Updated\" : false}";
then you need to "parse" the string into a json object, then get those "values" for the "keys"
like:
QJsonDocument doc1 = QJsonDocument::fromJson(str3.toUtf8());
QJsonValue company = doc1["Company Name"];
QJsonValue dept = doc1["Department"];
QJsonValue number = doc1["Number"];
QJsonValue updated = doc1["Updated"];
qDebug()<< "Company: " << company.toString();
qDebug()<< "Department: " << dept.toString();
qDebug()<< "Number: " << number.toInt();
qDebug()<< "Updated: " << updated.toBool();
your output will look like:
Company: "ABC"
Department: "TESTING"
Number: 123
Updated: false

How to write a prepared update query?

I've been trying to write an update function that takes the user to be updated(usr), the flag which then translates to the field to be updated and the new value. Here's the function,
bool DBManager::updateDB(User* usr, int flag, QVariant& value)
{
QSqlQuery query;
bool status = false;
QString temp_value = "";
QList<QString> fieldlist = {"First_Name", "Last_Name", "Email", "Username", "Password"};
QString field = fieldlist.at(flag);
if (field == "First_Name") {
usr->setFirstName(value.toString());
temp_value = usr->getFirstName();
} else if (field == "Last_Name") {
usr->setLastName(value.toString());
temp_value = usr->getLastName();
} else {
qDebug() << "invalid option";
}
query.prepare("UPADATE Users SET :field = :newValue WHERE Username = :Username");
query.bindValue(":field",field);
query.bindValue(":newValue",temp_value);
query.bindValue(":Username",usr->getUserName());
qDebug() << query.boundValues();
if (m_db.isOpen()){
if (query.exec()){
status = true;
qDebug() << "DATABASE:: Record update successful";
} else {
qDebug() << "DATABASE:: Record update unsuccessful - " << query.lastError();
}
} else {
qDebug() << "DATABASE:: not open ";
}
return status;
}
When I run the code I get an error. Here is the output:
QMap((":Username", QVariant(QString, "zielinkin1"))(":field", QVariant(QString, "Last_Name"))(":newValue", QVariant(QString, "Thibos")))
DATABASE:: Record update unsuccessful - QSqlError("", "Parameter count mismatch", "") User not updated DATABASE:: database closed
How to fix this?
Cause
First problem
It is not hard to guess, that value binding works only for values, not for field names.
For more info, please read about Inserting, Updating, and Deleting Records.
Second problem
Found by #JimCastro:
You have a typo in your query. UPADATE should be UPDATE.
Solution
Use a string concatenation to form your prepared query.
Example
Instead of
query.prepare("UPDATE Users SET :field = :newValue WHERE Username = :Username");
write
query.prepare("UPDATE Users SET " + field + " = :newValue WHERE Username = :Username");
Delete or comment this line
query.bindValue(":field",field);

Libreoffice API (UNO): need to change user's xTextField text

Is there any proper way to change text in the user's created xTextField using C++ UNO?
These fields names are com.sun.star.text.fieldmaster.User.[FIELD NAME]
I tried this before, but it didn't help:
Libreoffice API (UNO) : text and data from xTextField
Also I've tried something like this but still didn't help:
// current_field - xTextField I got before
Reference<XText> xText = Reference<XText>(current_field, UNO_QUERY);
if (!xText.is())
{
qDebug() << "XText FROM xTextField IS NULL!";
return;
}
OUStringBuffer bufText;
bufText.append( new_value.utf16() );
std::stringstream textStr;
textStr << bufText.toString();
xText->setString( bufText.toString() );
Any suggestions?
Did you read section 5.18 of Andrew's Macro Document as recommended in my other answer? Here is Listing 5.49 translated into C++. It seems there is a bug in that listing because I had to add "." to make it work.
OUString sName = OUString::createFromAscii("Author Name");
OUString sServ = OUString::createFromAscii("com.sun.star.text.FieldMaster.User");
OUString sFieldName = sServ + OUString::createFromAscii(".") + sName;
Reference< XMultiServiceFactory > xDocFactory (xTextDocument, UNO_QUERY);
if (xNamedFieldMasters->hasByName(sFieldName))
{
fieldMaster = xNamedFieldMasters->getByName(sFieldName);
Reference< XPropertySet> xProps (fieldMaster, UNO_QUERY);
Any aContent;
aContent <<= OUString::createFromAscii("Andrew Pitonyak");
xProps->setPropertyValue(OUString::createFromAscii("Content"), aContent);
}
else
{
fieldMaster <<= xDocFactory->createInstance(sServ);
Reference< XPropertySet> xProps (fieldMaster, UNO_QUERY);
Any aName;
aName <<= sName;
xProps->setPropertyValue(OUString::createFromAscii("Name"), aName);
Any aContent;
aContent <<= OUString::createFromAscii("Andrew Pitonyak");
xProps->setPropertyValue(OUString::createFromAscii("Content"), aContent);
}
If this code is run on a blank document, the newly created field can be seen by going to Insert -> Fields -> More Fields, Variables, User Field.

Create a JPA Named Query with conditional where clause based on user value selections

I am rewriting an existing application and am required to use the existing application queries using JPA 2. How do I write a Named Query that replaces a dynamic query that will add sections to the where clause based on a value selection. In other words, if a value is selected from a drop down box, I will add a AND/OR section to the where clause. If not, that where clause section is omitted. For example:
int paramIdx = 0;
String query = "SELECT * FROM ANIMAL_TABLE WHERE...something";
String whereClause = "";
if(canine!= null and canine.trim().length() > 0) {
whereClause += " AND canine_type = :" + (paramIdx + 1) + viewObject.setWhereClauseParam(paramIdx, canine);
paramIdx++;
}
if(cat != null and cat.trim().length() > 0) {
whereClause += " AND cat_type = :" + (paramIdx + 1) + viewObject.setWhereClauseParam(paramIdx, cat);
}
I'm wondering if there is a way to accomplish this using JPA. Any ideas or suggestions would be helpful.

having an issue with an if then statement using vbYesNo

I am trying to create a script that will ask the user if they want to set a network printer as their default. My problem is that no matter what they select (yes or no) it set it up as the default and it always echo's my the echo statement under else. Can someone tell me what I am doing wrong?
` ' Printers.vbs - Windows Logon Script.
printername = "DCPTTEAM462W"
server = "DCDEPLOY03"
Dim objectNetwork, printer
printer = "\\DCPRINT03\DCPTTEAM462W"
Msgbox printername & " will now install on your computer.",0, "Add printer" & printername
intRespnseY = Msgbox("Would you like " & printername & " to be set as your default printer", vbYesNo, "Set as Default")
If intResponseY = vbNo Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection printer
WScript.Echo "DCPTTEAM462W was added as a printer."
Else
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection printer
objNetwork.SetDefaultPrinter printer
WScript.Echo "DCPTTEAM462W has been set as your default printer."
End If
`
You have a typo:
intRespnseY = Msgbox(....
Should be
intResponseY = Msgbox(....
Use
Option Explicit
to avoid blunders like:
intRespnseY = Msgbox("...")
If intResponseY = vbNo Then
(mark the missing "o")