Adding fragment to part of XML view in SAPUI5

To add a fragment to part of the page in XML view first you need to create the XML Fragment i.e Display.fragment.xml
Then in the parent XML view add the VBox where you want to add the fragment after clicking a button


Create the function that will call the fragment after clicking the button

//To show the fragment
_showFormFragment: function(sFragmentName) {
var oFormFragment = sap.ui.xmlfragment(this.getView().getId(), "omsslist.view." + sFragmentName, this);
var vBox = this.byId('displayFragment');
vBox.destroyItems();
vBox.addItem(oFormFragment);
},

Then inside the button click action add the code

this._showFormFragment("Display");

 

Attach file grammatically to a node in Drupal 7

The below code shows how to upload a file to the field of the node programmatically

$file_path = 'sites/default/files/'.$fname;

$node = node_load($nid);
$file = new stdClass;
$file->uid = $node->uid;
$file->filename = pathinfo($file_path, PATHINFO_BASENAME);
$file->uri = $file_path;
$file->filemime = file_get_mimetype($file_path);
// Make it permanent, otherwise it will get deleted later.
$file->status = FILE_STATUS_PERMANENT;

// Save file object to make it a 'managed file'.
file_save($file);

// We will save file under this location. public:// if it is a public file
$destination = 'private://';

// Make sure destination directory exists before moving files to that path.
// This will create directory if it does not exists.
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);

// Now attach file to the file field.
$node->field_attachement[$node->language][0] = (array) $file;

// Default file type field comes with this extra properties.
$node->field_attachement[$node->language][0]['display'] = 1;
$node->field_attachement[$node->language][0]['description'] = 'Description of the file';

// Save node to make the attachment effective.
node_save($node);

You need to upload your file to the server first then run the code after setting the path of the file on your server.
$file_path = ‘sites/default/files/’.$fname;
Just change the $nid variable to your variable

Using drupal 7 field collection programmatically

Insert field collection


//Create the Field Collection entity
$item = entity_create('field_collection_item', array('field_name' => 'myfieldcoll_machine_name'));
//set the hosting node 
$item->setHostEntity('node', $myNode_object);

//Fill your fields
$item->field_myfield[LANGUAGE_NONE][0]['value'] = 'My Value;

//Save the entity
$item->save();
$myNode_object->myfieldcoll_machine_name[LANGUAGE_NONE][]['value'] = $item->item_id;

Continue reading

Using mock data in SAPUI5

To use the data in a mock file that is saved locally in the “model” folder you need to loadData from that file as follows:

 

	
onInit: function() {
// set data model on view
//var data = {
//"studentSet": [{
//"name": "Kareem",
//"class": "KG1",
//"Nationality": "Palestinian"
//}, {
//"name": "Ahmad",
//"class": "KG3",
//"Nationality": "Saudi"
//}]
//};
//var oModel = new JSONModel();
//oModel.setData(data);


var oModel = new JSONModel();
// Load JSON in from the file
oModel.loadData("model/myData.json");

this.getView().setModel(oModel);

},

Continue reading

SAPUI5 formatter function with two parameters

Suppose we have a text field where the value depends on another value, in this case we have to pass the two values in the formatter.

See the example below:

Textfield should be like this:
<Text text=”{ parts : [ ‘var1’, ‘var2’ ], formatter: ‘.formatter.approverName’ }”/>

and the formatter code is:

approverName : function (sPosition, sName) {
	if (sPosition === 'GR Admin') {
		return "Custom";
	}
	return sName;
},

 

Posting date to SAP via OData using SAPUI5 Datepicker

Suppose that you have a datepicker sapui5 control and you want to pass the value of the datepicker to be posted to SAP using oData

<DatePicker id=”travelDate” />

var travelDate = this.byId('travelDate');
var dateVal = travelDate.getDateValue();

var dateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern : "yyyy-MM-ddTKK:mm:ss" });
var dateOdataVal = dateFormat.format(dateVal);

Then use the dateOdataVal in your oData values

Export drupal 7 views as excel xlsx

To export drupal 7 views as xlsx files or other types like xls and cvs you can use two modules.

first one is https://www.drupal.org/project/views_data_export

and for xlsx support you need https://www.drupal.org/project/views_data_export_phpexcel

 

Just enable the two modules and create your Data Extract view, and attach it to any page or block view

Creating and Deploying SAP Fiori Extension Project

To create the extension project in SapWebIDE choose new extension project and follow the simple steps where you decide the system and the application you want to extend

After you do the changes you want, you need to deploy this project to SAP System, to do that select your project and choose Deploy to ABAP Repository, then choose the system where you want to deploy your app with the package and transport request.

Note: if you cannot change the $TMP package then you need to apply the following sap notes: 2047506, 2046730.

After that you have to create the LPD_CUST and Semantic Object entries to create a tile on FLP for this extension.

Continue reading

How to find bad a node that makes search indexing to fail in Drupal 7

To find out which node is causing the indexing problem you have to modify the following in “modules/node/node.module”

 

function node_update_index() {
  $limit = (int)variable_get('search_cron_limit', 100);

  // Store the maximum possible comments per thread (used for ranking by reply count)
  variable_set('node_cron_comments_scale', 1.0 / max (link is external)(1, db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'))));
  variable_set('node_cron_views_scale', 1.0 / max (link is external)(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));

  $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid 
                            WHERE d.sid IS NULL OR d.reindex <> 0 
                            ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);

  while ($node = db_fetch_object($result)) {
    watchdog ('cron', "indexing node {$node -> nid}"); // ADD THIS LINE
    _node_index_node($node);
  }
}

After that go to “/admin/config/system/cron” to find the cron jobs, there you will find a job called “search_cron” , click on run then go to the logs to find which node is causing the problem

Common reason for the problem
Normally this problem happens because of some bad php in a node or because of a drupal_goto call in some php.

People often recommend disabling the module “PHP Filter”, clearing the cache, running cron, then enabling it again.and other solutions also recommend you try to reduce the number of items you index when cron runs.