Getting Document metadata (Document Type values) in liferay 7 - liferay-7

I am working on Liferay 7. I created a document type "My Documents" with field "Language" which is a selection dropdown with values "English", "French" and "Spanish". I uploaded a document and selected Language value as French. Now I am trying to get this Language value for the document but its returning blank. Below is the code I am using.
DDMStructure ddmStructure = null;
List<DDMStructure> structures = dLFileEntryType.getDDMStructures();
mainloop:
for (DDMStructure struct : structures) {
if (struct.getName((Locale.ROOT)).equalsIgnoreCase("My Document")) {
ddmStructure = struct;
break mainloop;
}
}
DLFileEntryMetadata fileEntryMetadata = null;
try {
fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), dlFileEntry.getFileVersion().getFileVersionId());
if(Validator.isNotNull(fileEntryMetadata)) {
ServiceContext serviceContextDLFile = new ServiceContext();
serviceContextDLFile.setCompanyId(companyId);
serviceContextDLFile.setAttribute("fileEntryTypeId", fileEntryTypeId);
serviceContextDLFile.setAttribute("fileEntryMetadataId", fileEntryMetadata.getFileEntryMetadataId());
serviceContextDLFile.setAttribute("DDMStorageId", fileEntryMetadata.getDDMStorageId());
serviceContextDLFile.setAttribute("fileEntryId", fileEntryMetadata.getFileEntryId());
serviceContextDLFile.setAttribute("fileVersionId", fileEntryMetadata.getFileVersionId());
DDMFormValues ddmFormValues = StorageEngineManagerUtil.getDDMFormValues(fileEntryMetadata.getDDMStructureId(), null, serviceContextDLFile);
List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues();
if(Validator.isNotNull(ddmFormFieldValues) && !ddmFormFieldValues.isEmpty()) {
for(DDMFormFieldValue formfieldValue : ddmFormFieldValues) {
if(formfieldValue.getName().equalsIgnoreCase("Language")) {
String languageRawName = formfieldValue.getValue().getString(Locale.US);
String language = languageRawName.replace("[\"", "").replace("\"]", "");
}
}
}
}
} catch (NoSuchFileEntryMetadataException nsfene) {
// LOGGER.error("ERROR:: ", nsfene);
} catch(PortalException portalException) {
// LOGGER.error("ERROR:: " , portalException);
}
I have not given any predefined value for Language field while creating Document Type. When I am giving any predefined value for Language field, the above code is returning that predefined value.
Please tell if I am missing something or there is any other approach do achieve this.

Stored data in document library documents is not internationalized.
I think you have to always use the default language of the instance.

Related

Adding Values to Custom Attribute using App Script

I have a requirement of adding Value to Custom attribute in G Suite for bulk users, I have added address and other field using App script but don't know how to add values to a custom attribute named "Enhanced Desktop Security" as shown in the image below.
Value to be added is using App Script is: "un:Windows"
Request your help with the Script.
I have been working on this and came to know that 1st you have to identify the schemas of the custom attribute here : https://developers.google.com/admin-sdk/directory/v1/reference/users/list Once you do that you can use the below script. Please make sure that you change the schema in the below script.
Mention "User Email ID", "Value", "Updation Status" in Cloumn A,B,C, respectively in sheet.
function updateCustomE() {
var ss = SpreadsheetApp.openById(""); // Mention ID of the spreadsheet here.
var sheet = ss.getSheetByName(""); // Mention Name of the sheet here.
var values = sheet.getDataRange().getValues();
var fileArray = [["Updation Status"]]
for(i=1; i <values.length; i++)
{
var userKey = values[i][0]
var customValue = values [i][1]
try{
var status = "Value not updated"
var status = AdminDirectory.Users.update({
"customSchemas": {
"Enhanced_desktop_security" : {
"Local_Windows_accounts" : [
{
"type": "custom",
"value": customValue
}
]
}
}
}, userKey);
if (status != "Value not updated"){
status = "Value updated Successfully"
}
}
catch (e) {
Logger.log(e.message)
var status = e.message
}
fileArray.push([status])
}
var range = sheet.getRange(1, 3, fileArray.length, 1).setValues(fileArray)
}

Custom properties are not updated for the word via openXML

I am trying to update custom properties of word document thru Open XML programming but it seems the updated properties are not getting saved properly for the word document. So when I opening document after successful execution of the update custom property code, I am getting the message box which is "This document contains field that may refer to other files; Do you want to update the fields in the Document?" If I am pressing 'NO' button then all the update properties would not be saved to the document. If we are going for yes option then it will update properties but I need to save the properties explicitly. Please suggest to save properties to the document without getting confirmation message or corrupting the document. :)
the code snippet is given as below,
public void SetCustomValue(
WordprocessingDocument document, string propname, string aValue)
{
CustomFilePropertiesPart oDocCustomProps = document.CustomFilePropertiesPart;
Properties props = oDocCustomProps.Properties;
if (props != null)
{
//logger.Debug("props is not null");
foreach (var prop in props.Elements<CustomDocumentProperty>())
{
if (prop != null && prop.Name == propname)
{
//logger.Debug("Setting Property: " + prop.Name + " to value: " + aValue);
prop.Remove();
var newProp = new CustomDocumentProperty();
newProp.FormatId = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}";
newProp.Name = prop.Name;
VTLPWSTR vTLPWSTR1 = new VTLPWSTR();
vTLPWSTR1.Text = aValue;
newProp.Append(vTLPWSTR1);
props.AppendChild(newProp);
props.Save();
}
}
int pid = 2;
foreach (CustomDocumentProperty item in props)
{
item.PropertyId = pid++;
}
props.Save();
}
}
I am using .Net framework 3.5 with Open XML SDK 2.0 and Office 2013.
Try this one
var CustomeProperties = xmlDOc.CustomFilePropertiesPart.Properties;
foreach (CustomDocumentProperty customeProperty in CustomeProperties)
{
if (customeProperty.Name == "DocumentName")
{
customeProperty.VTLPWSTR = new VTLPWSTR("My Custom Name");
}
else if (customeProperty.Name == "DocumentID")
{
customeProperty.VTLPWSTR = new VTLPWSTR("FNP.SMS.IQC");
}
else if (customeProperty.Name == "DocumentLastUpdate")
{
customeProperty.VTLPWSTR = new VTLPWSTR(DateTime.Now.ToShortDateString());
}
}
//Open Word Setting File
DocumentSettingsPart settingsPart = xmlDOc.MainDocumentPart.GetPartsOfType<DocumentSettingsPart>().First();
//Update Fields
UpdateFieldsOnOpen updateFields = new UpdateFieldsOnOpen();
updateFields.Val = new OnOffValue(true);
settingsPart.Settings.PrependChild<UpdateFieldsOnOpen>(updateFields);
settingsPart.Settings.Save();
you have to update your document fields on open.

Switch Statement for Field Value

I am trying to set up a customization that will dynamically display values in a series of fields using a switch statement.
If we focus on one field I have a String List
public static class SMSPlans
{
public const string A = "A";
public const string B = "B";
public const string C = "C";
public const string Z = "Z";
}
[PXDBString(2, IsUnicode = true)]
[PXDefault(SMSPlans.Z)]
[PXUIField(DisplayName = "SMS Plan Selected")]
[PXStringList(
new string[]
{
SMSPlans.A,
SMSPlans.B,
SMSPlans.C,
SMSPlans.Z
},
new string[]
{
"Plan A",
"Plan B",
"Plan C",
"No Text Plan"
})]
I would like to when this field is set to any one of the allowable values populate a series of fields with corresponding fixed values as shown in the image below (0 is default value currently would show up if any plan is selected)
I planned on using the formula functions and using a switch statement to set my desired value that would look like
[PXFormula(null,typeof(Switch<Case<Where<Current<UsrMPSMSPlanSelected, Equal<SMSPlans.A>>,0>))]
I am stuck however on:
How I need to use the _RowSelect() or other event handlers
What if any value would be stored in the database for these fields assigned by the switch statment
finally is this switch structured correctly as it is not currently working
From what I can tell you have a few ways to handle this.
1) With PXFormula attribute tags - your Switch definition is mostly correct in the sample above but depending on where you have it the PXFormula definition itself is incorrect. What I would do is put the PXFormula tag on the fields that need to be updated.
For example, if your field is UsrMinText use the following:
[PXFormula(typeof(Switch<Case<Where<UsrMPSMSPlanSelected,Equal<SMSPlans.A>>,{value if true},{value if false or more case statements}))]
2) Personally for this type of customization I would use an actual event method in the BLC to do this. A good example of this is in the help guide for the events.
protected void Batch_ManualStatus_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
Batch batch = (Batch)e.Row;
if (batch != null && e.NewValue != null)
{
switch ((string)e.NewValue)
{
case "H":
batch.Hold = true;
batch.Released = false;
batch.Posted = false;
break;
case "B":
batch.Hold = false;
batch.Released = false;
batch.Posted = false;
break;
case "U":
batch.Hold = false;
batch.Released = true;
batch.Posted = false;
break;
case "P":
batch.Hold = false;
batch.Released = true;
batch.Posted = true;
break;
}
}
}
In either method, the value that will be stored in the database is whatever you specify in either the {True}/{False} values for PXFormula or the values specified in the actual switch methods.
One thing to remember is field order in the DACS is important. I'd read through the training information and help guides for more information on this.

CRM 2011 : Plugin to create duplicate records

i created a simple plugin to create a duplicate record that refers to the parent record.
Here is my code
var pluginExecutionContext = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
abc= pluginExecutionContext.InputParameters["Target"] as Entity;
if (pluginExecutionContext.Depth == 1)
{
Guid abcId = abc.Id;
Entity abcCopy = new Entity("mcg_abc");
if (abc.Attributes.Contains("mcg_abccategoryoptioncode"))
{
abcCopy.Attributes["mcg_abccategoryoptioncode"] = abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode");
}
if (abc.Attributes.Contains("mcg_effectivedate"))
{
abcCopy.Attributes["mcg_effectivedate"] = isp.GetAttributeValue<DateTime>("mcg_effectivedate");
}
if (abc.Attributes.Contains("mcg_startdate"))
{
abcCopy.Attributes["mcg_startdate"] = isp.GetAttributeValue<DateTime>("mcg_startdate");
}
if (abc.Attributes.Contains("mcg_enddate"))
{
abcCopy.Attributes["mcg_enddate"] = isp.GetAttributeValue<DateTime>("mcg_enddate");
}
if (abc.Attributes.Contains("mcg_amendeddate"))
{
abcCopy.Attributes["mcg_amendeddate"] = isp.GetAttributeValue<DateTime>("mcg_amendeddate");
}
if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
{
//Some more fields;
}
else
{
//Some more fields;
}
// SOme more fields;
abcCopy.Attributes["mcg_parentabc"] = new EntityReference("mcg_abc", abc.Id);
service.Create(abcCopy);
}
Now the problem is all the fields before the below check are getting copied
if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
However fields after this check are not getting copied.
Please if anybody could suggest what mistake i have made.
In case you take field from Target - this field was updated on a client side. In case field was not updated - it would not be in Target. You should use Images to get values of unchanged fields.
The field must be empty so a exception may arise. Try to use the plugin image or change your code to this way:
if (abc.Attributes.Contains("mcg_abccategoryoptioncode")){
if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
....

Jira: How to obtain the previous value for a custom field in a custom IssueEventListener

So how does one obtain the previous value of a custom field in a Jira IssueEventListener? I am writing a custom handler for the issueUpdated(IssueEvent) event and I would like to alter the handler's behavior if a certain custom field has changed. To detect the type of change I would like to compare the previous and current values.
(I'm am not asking about how to obtain its current value - I know how to get that from the related Issue)
I am developing against Jira 4.0.2 on Windows.
Is the best way to scan the change history for the last known value?
List changes = changeHistoryManager.getChangeHistoriesForUser(issue, user);
I'm assuming the original poster is writing a JIRA plugin with Java. I cannot be certain of how to accomplish this task in JIRA v4.0.2, but here is how I managed to do so with JIRA v5.0.2 (the solutions may very well be the same):
public void workflowEvent( IssueEvent event )
{
Long eventTypeId = event.getEventTypeId();
if( eventTypeId.equals( EventType.ISSUE_UPDATED_ID ) )
{
List<GenericValue> changeItemList = null;
try
{
changeItemList = event.getChangeLog().getRelated( "ChildChangeItem" );
}
catch( GenericEntityException e )
{
// Error or do what you need to do here.
e.printStackTrace();
}
if( changeItemList == null )
{
// Same deal here.
return;
}
Iterator<GenericValue> changeItemListIterator = changeItemList.iterator();
while( changeItemListIterator.hasNext() )
{
GenericValue changeItem = ( GenericValue )changeItemListIterator.next();
String fieldName = changeItem.get( "field" ).toString();
if( fieldName.equals( customFieldName ) ) // Name of custom field.
{
Object oldValue = changeItem.get( "oldvalue" );
Object newValue = changeItem.get( "newvalue" );
}
}
}
}
Some possible key values for changeItem are:
newvalue
oldstring
field
id
fieldtype
newstring
oldvalue
group
For many of the custom field types Object oldValue is probably just a String. But I don't think that's true for every case.
Try this example :
String codeProjetOldValue= "";
List<GenericValue> changeItemList = issueEvent.getChangeLog().getRelated("ChildChangeItem");
for (GenericValue genericValue : changeItemList) {
if(champCodeProjet.equals(genericValue.get("field"))){
codeProjetOldValue=genericValue.getString("oldstring");
break;
}
}
Note that : champCodeProjet is the name of customfield.